- Home /
Collision2D.relativeVelocity should be 0?
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.
Another possible interpretation of this variable is that it only gives reliable information at the impact moment, and thus should only be used in an oncollisionENTER function ins$$anonymous$$d of oncollisionSTAY.
I thought I found the problem but it still persists. For the moment I'm working around that by using the other rb velocity.
Answer by MelvMay · Mar 15, 2016 at 07:31 AM
This is a known bug that was reported fairly recently. It will be fixed ASAP.
Sorry for the confusion it has caused.
Your answer
Follow this Question
Related Questions
More realistic physics on child collisions 2D 0 Answers
Collision Between 2D Rigidbodies is Jittery (No Movement) 1 Answer
How to disable collisions without disabling rigidbody? 1 Answer
Workarounds for Higher Control When Using Physics2D? 0 Answers
Calling a Collision from code OR not simulating drag/gravity 0 Answers