beyretb / AnimalAI-Olympics

Code repository for the Animal AI Olympics competition
Apache License 2.0
573 stars 84 forks source link

Can i get the velocity of the agent? #77

Closed Cospui closed 5 years ago

Cospui commented 5 years ago

Hi, I read the document and found that obs[1] can show the velocity of the agent. And i read several issues about the velocity, but i still find it a little bit hard to follow. I build a simple environment:

!ArenaConfig
arenas:
  0: !Arena
    t: 0
    items:
    - !Item
      name: Agent
      positions:
        - !Vector3 {x: 1, y: 0, z: 1}
      rotations: [0]

and use the following code to control:

action = [1, 0]
dis = (0.0, 0.0, 0.0)
for i in range(40):
    obs,reward,done,info = env.step(action)
    dis += obs[1]
    print( obs[1] )

print()
print( dis )

and here is what i get:

[ 0.         -0.35398483  0.84673786]
[ 0.00000000e+00 -2.83241272e-03  3.00361156e+00]
[ 0.00000000e+00 -1.90734863e-05  5.09659433e+00]
[0.         0.         6.94981289]
[0.         0.         8.58943081]
[ 0.          0.         10.04006004]
[ 0.          0.         11.32348442]
[ 0.          0.         12.45897579]
[ 0.          0.         13.46358585]
[ 0.          0.         14.35240078]
[ 0.          0.         15.13876629]
[ 0.          0.         15.83449364]
[ 0.          0.         16.45003128]
[ 0.          0.         16.99461937]
[ 0.          0.         17.47643471]
[ 0.          0.         17.90271568]
[ 0.          0.         18.27985954]
[ 0.          0.         18.61353302]
[ 0.          0.         18.90874672]
[ 0.          0.         19.16993141]
[ 0.          0.         19.40101242]
[ 0.          0.         19.60545921]
[ 0.          0.         19.78634071]
[ 0.          0.         19.94637299]
[ 0.          0.         20.08795738]
[ 0.         0.        20.2132225]
[ 0.        0.       20.324049]
[ 0.          0.         20.42210007]
[ 0.         0.        20.5088501]
[ 0.          0.         20.58560181]
[ 0.          0.         20.65350723]
[ 0.          0.         20.71358681]
[ 0.         0.        20.7667408]
[ 0.          0.         20.81376648]
[ 0.          0.         20.85537148]
[ 0.         0.        20.8921814]
[ 0.          0.         20.92474747]
[ 0.          0.         20.95355988]
[ 0.         0.        20.9790535]
[2.77410321e-15 0.00000000e+00 0.00000000e+00]

[ 2.77410321e-15 -3.56836319e-01  6.49327307e+02]

as you can see the agent use 39 steps to reach the other side, i guess it means that each step contributed equally on the movement, i.e. on a 40x40 map, each step will contribute 1. But the obs[1][2] is different from step to step, it's changing and I don't know what that means. What is meanning of obs[1][2]? And how can i get the velocity of the agent?

THANKS!

beyretb commented 5 years ago

i guess it means that each step contributed equally on the movement, i.e. on a 40x40 map, each step will contribute 1.

No, it's not a constant jump forward. The velocity is computed by Unity physic's engine. When you move forward/backward you apply a force to the agent, its velocity is then computed depending on friction, drag, momentum etc.

What is meanning of obs[1][2]?

It is the z (forward) component of the agent's velocity in its local reference frame.

And how can i get the velocity of the agent?

in your example obs[1] is the velocity of the agent along (x,y,z)

Have a look at this discussion to see how you can work out the time component of the velocity.

beyretb commented 5 years ago

I m closing this topic due to inactivity, please reopen if needed