- Home /
How to get 'real' velocity of an object and not the input velocity?
I have a player controller where the player uses velocity to move using physics. Now if I hit a wall, the input velocity is still the same, but the player stops moving. I need a way to get the player's velocity (real) when he is running into a wall because I am constantly feeding 25 into the player's z velocity, but what if the player is on a wall? He is then not moving at all, but the velocity on z still gives 25.
can you add your code? Because that kind of sounds like you set the velocity first and then check for it's value.
Yeah, this was my velocity code:
Vector3 vel = transform.forward * movespeed; vel.y = rb.velocity.y.
//now if I bump into a wall, this code is still running, but I want the real velocity to check later on for something and not what I am inputting into this.
Answer by jamesvhyde · Jul 27, 2020 at 05:45 PM
If you set the rigid body's z velocity to 25, it's definitely going to be 25 when you try to read it. Make sure you check it before you set it, in whatever script you're setting it.
Answer by Llama_w_2Ls · Jul 27, 2020 at 05:40 PM
Yup, rigidbody.velocity should work. Credit to @nanavatidhruvik
Your answer
Follow this Question
Related Questions
Restrict a Players Movement Up a Slope 1 Answer
How to detect movement? 1 Answer
How to move a gameObj by cicking/ touching another gameobj? 0 Answers
can't move player rigidbody.velocity 1 Answer
Rigidboy.velocity with integer? 1 Answer