The phalanx wasn't a static defensive formation. It was an aggressive line of spears that moved unstoppably across the battlefield until the enemy were engaged. Only then would flanking actions occur.
I'm simplifying a lot there, but in essence it is what you should do with your phalanx line. Move the formation forward. Attack!
You might find it useful to group the formation and then march them up to the enemy. using shift+right click helps to keep everything in order.
Bookmarks