If a unit fails a Panic test:
Brought about by heavy casualties. Pivot the unit on the spot (ignoring other units) so that it is facing directly away from the unit/terrain that caused the most casualties in that phase – it then flees as described in the Movement chapter.
Brought about by any other reason. Pivot the unit on the spot (ignoring other units) so that it is facing directly away from the closest enemy unit, and then flees as described in the Movement chapter.
Providing that the panicked unit doesn't carry itself off the board with its first flee move, you'll have a chance to rally it in later turns, as we discussed earlier.