- Home /
How would you check the local velocity of a rigidbody on a single axis
I'm implementing a move which freezes the player's rotation, since it uses the player's rotation for the move ,I need to know when the player's velocity going side-ways reaches zero to unfreeze the rotation. My character's rotation is based off of velocity, so I need their side-ways velocity to be zero before I unfreeze the rotation so they are still facing forward.
rigidbody.velocity is basically a Vector3 struct that represents the rigidbodys speed (units per second) in x, y and z directions in the world space. So you can check, for example, velocity.x float value to get the speed in x-axis direction. When rigidbody is not moving in x-axis direction then the velocity.x is zero.
Answer by Patrickmol · Jun 17, 2021 at 11:25 AM
Use those to check the speed, THEY NEVER GO BELOW 0
rigidbody.velocity.x
rigidbody.velocity.y
rigidbody.velocity.z
rigidbody.velocity.magnitude //All the axis togheter
What do you mean they never go below 0? x, y and z values do go below zero depending on the objects movement direction along the corresponding axis. The magnitude, of course, is never negative.
Answer by SalahChafai160 · Jun 17, 2021 at 02:41 PM
if I'm understanding your question correctly, this should do it: Mathf.Abs(rb.velocity.x)
Your answer
Follow this Question
Related Questions
Bullet not moveing forward,Bullet not moveing 1 Answer
Multiple Cars not working 1 Answer
Multi-lane endless runner. How to toggle lanes? 1 Answer
Distribute terrain in zones 3 Answers