- Home /
Question by
TurboHermit · Jun 29, 2013 at 10:40 AM ·
rigidbodyvector3velocityspeed
Comparing rigidbody speeds
Hi, I'm trying to see if a rigidbody is under a certain speed.
I want to apply this code:
other.rigidbody.velocity = other.rigidbody.velocity.normalized * BounceForce;
if the rigidbody isn't already going faster than that. However, I have no clue how read the current speed, aside from the velocity. Unless I can compare theoretical velocity with the current one, that would do too I guess. Is there a way to see how fast the rigidbody is going and how fast it will be when the BounceForce is applied?
Comment
Answer by robertbu · Jun 29, 2013 at 05:13 PM
I think what you are looking for is '`other.rigidbody.velocity.magnitude`'. Something like this:
var newVelocity = other.rigidbody.velocity.normalized * BounceForce;
if (newVelocity.magnitude > other.rigidbody.velocity.magnitude)
other.rigidbody.velocity = newVelocity;