i'm assuming in reality most empires/kingdoms didn't have nice matching sets of armour (contrary to how they're depicted on TV), so in the middle of a chaotic battle how would you know whether someone was on your side or the enemy's side?
In many cases, ancient battles aren't as depicted on TV. Two armies didn't meet then descend into a series of single combats. The most important thing in a large scale ancient battle was maintaining your line. i.e. keeping your soldiers in a coherent, aligned formation. Once the line broke, you're dangerously close to a rout. Therefore, most of the time during functional battles you can identify your enemy since they're all in a continuous formation, generally facing into your own continuous formation, instead of being like a football match where they're mixed in with your own army throughout the field.
When the formation broke, you could identify your opponents army as "the ones that are running away".
Sources:
Caesar's Gallic Wars for a story about how maintaining a continuous line was so important that Caesar ran in front of his line to encourage his front liners to catch him up and re-establish the line
Donald Kagan's the Peloponnesian War about the importanceabout maintaining the line during hoplite warfare. Even further, when talking about radical tactics e.g. Epaminondas' oblique formation at the battle of Leuktra, it still relies on your army being in a continuous formation (although in this case an oblique one)
EDIT: Epaminondas, not Pagondas