I’m making a physics based movement and I wanted to use this variable to get the ground relative speed when the player is standing on it. This way I can make the controls relative to moving platforms. The problem is that it returns zero when I’m on moving platforms and I don’t understand why. I thought I could be because both needed to be rigidbodies but my tests show that doesn’t work either.
In order to reproduce you can use these simplified scripts:
for the player add a rb2d with a collider and this to the oncollisionstay2d function
void OnCollisionStay2D ( Collision2D C ){
print("ground speed = "+C.relativeVelocity.x);
}
For the moving platform you can make it move however you want, it doesn’t work for me in any way I can think of. Just a transform with a collider, adding a rb and changing its velocity doesn’t work and making it a kinematic rb doesn’t work either.
What I get here is that the velocity of the contact points are good when the player is running over the other objects, but when I stand still on a moving platform it gives me zero relative movement and the platform slides beneath the player’s feet. It’s like this variable is giving me the world frame velocity of the player rigidbody instead of relative velocity of the collision.
Any ideas on why? The doc doesn’t give enough details, so I don’t even know if this is by design.