Hi guys
How can I determine the world velocity of a transform/rigidbody component?
thanks
Hi guys
How can I determine the world velocity of a transform/rigidbody component?
thanks
rigidbody.velocity
–Eric
Thanks erci, the problem is that I get an message saying that I cannot convert vector3 to int. I need to limit my speed value to e.g 100 or whatever…
sorry, “eric” ![]()
I got that problem sorted, but now I realised that the velocity gives the 3 vectors seperately, so I need to find a way to convert this into a constant speed value, irrespective of which direction I’m going. Any body have some ideas?
A Vector3 has a value “magnitude” which holds this value.
Something like myVelocity = rigidbody.magnitude, it is basically sqrt(x^2 + y^2 + z^2). You can tell that it would be a little expensive to calculate, especially for many objects, but that’s what you need.
Thanks for the help. one more question…
How can I cast this…
rigidbody.velocity.magnitude;
…to a int value? I noticed that, if I times the above code by 1…
rigidbody.velocity.magnitude *1;
…it gives me a consistant value, but shurely that can’t be the correct way???
guys!!!
sorry, I’m an idiot! just ignore my previous post and use
speed = rigidbody.velocity.magnitude;
It gives a rounded value.