I want to know velocity of my object. I have rigidbody.velocity, but i cant save it to my var Speed I try int or float but nothing work. Can u help me?
Maybe this can help you
Velocity is a Vector3. So you can do:
var myVelocity = rigidbody.velocity;
or
var myVelocity : Vectgor3 = rigidbody.velocity;
If you are just interested in the speed of the object, you can use the magnitude of the velocity:
var speed : float = rigidbody.velocity.magnitude;
javascript right?
rigidbody.velocity is a Vector3 that as you know Stores the velocity
because of that you must put it in a Vector3. Here’s a cool way I found out how to do it:
-
private var holdMyVelocity : Vector3;
-
holdMyVelocity = rigidbody.velocity;
“but I can’t see it” go to the top corner of the inspector where there’s a lock. just right of it there’s a tiny drop down. click it and go to Debug. Now you can see loads of information you normally wouldn’t be able to. The bigest benefit from this is that if you ever need to see your velocity again… you could always reactivate debug mode.