This code is good and very used..but doesn't works well on simul modes. Plus, P2BodyDist gives the distance of P2 FRONT CLSN position, not his X axis position. P2DistX give you p2 X axis position though.
For simul modes, you should use EnemyNear:
[State -2, Debug Info]
type = DisplayToClipboard
trigger1 = roundstate > 0
text = "P2 Distance X: %f, P2 Distance Y: %f"
params = (Pos X-(enemyNear, Pos X)), (Pos y-(enemyNear, Pos y))
It will return a negative value, because you're on a negative position from p2.