Cordyceps is a bit different in that it makes the host insect clamp down on a branch or twig until death so that when the fruiting body grows out of the host, its spores are spread through the air, where it can infect similar insects.
What OP is talking about sounds more like the lancet liver fluke, which has a stage of its lifecycle inside an ant and a stage inside a grazing animal, so it makes an infected ant climb to the top of a grass stalk. Amazingly, the ants only do this from dusk till dawn, resuming their normal activities if they haven't been eaten by dawn. The rationale seems to be that being exposed to the hot sun during the day could quickly kill the ant along with its passenger flukes