# Symmetric Soccer Vector Observations

The mlagents soccer example uses Raycast observations. I was wondering, for a similar soccer environment, how would one go about using Vector observations instead. The environment consists of 2 teams, 1 player on each team, and a ball. I would think, the velocities of the rigid bodies of all three and the positions of all 3, I would think this would be adequate observations. My confusion comes in that the players from opposing teams share the same Behaviour scripts, the only difference being different team id’s. But when it trains using self-play it would only train from one perspective at a time (my understanding, could be wrong).

So do I add the vector observations as linked to the team id’s? So that the observations stay the same no matter which team’s agent is being trained? As in:
player 1 position
player 2 position
ball position

Or do I add them as player vs opponent? So as to take into account perspective? As in:
player position (if its training with team 1 than team 1’s agent will be “player”, and same with team 2)
opponent position (if its training with team 1 than team 2’s agent will be “opponent”, and vice-versa)
ball position

I hope this question makes sense. I feel like this should be pretty straightforward but for some reason its giving me a headache. Any insight would be appreciated.

Also, what’s performance like Ray Observations vs Vector Observations? My gut says Vecs should be cheaper and faster as the values are much more specific where as Rays are more general feelers in the environment. But I’m interested if anyone has first hand experience of the pros and cons of each.

You’d need to add all the positions, both teammate and opponent, from the player’s perspective. You can use the Unity built-in functions in the Transform class to transform absolute positions and directions to the local space (e.g. Unity - Scripting API: Transform.InverseTransformPoint).

Vector observations should train a bit faster, but you still might want raycasts to detect walls. You might also lose some of the order invariance (e.g. if opponent 1 was left of opponent 2, vs. opponent 2 left of opponent 1) which will take some time to learn.