- Home /
Compare Rigidbody.velocity
I want to compare the Rigidbody.velocity of two objects to see which is moving the fastest.
How would I go about doing that.
Answer by MT369MT · May 21, 2018 at 12:14 PM
if (Rigidbody1.velocity.magnitude > Rigidbody2.velocity.magnitude) { //First GameObject is faster }
When you only want to compare, and don't need the exact value, it is better to use Vector#.sqr$$anonymous$$agnitude
, which does not call a square root (which is relatively slow). That said, probably it won't make a difference, and it might be unnecessary optimisation.
Your answer
Follow this Question
Related Questions
Handling colliders on hundreds of asteroids (not procedural asteroids) ...URGENT 3 Answers
Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers
Make rigidbody walk like character controller 6 Answers
Set Rigidbody.velocity for an instantiated object 1 Answer
physics culling mask? 1 Answer