Source: Warhammer Armies Project: Unofficial 9th Edition (v2.2)
Direction of FlightURL Copied!
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 feeing directly away from the unit/terrain that caused the most casualties in that phase – it then flees as normal. If there is nothing to flee from (for example, the damage caused by a miscast from a Wizard in the unit). Pivot the unit on the spot (ignoring other units) so that it is facing directly away from the closest enemy unit.
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 normal.
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.