- Home /
The question is answered, right answer was accepted
How do I make rigidbody.velocity in local space?
I'm trying to make the velocity of an object into local space. All I know how to do is:
rigidbody.velocity = Vector3(0,0,yourVelocity)
Only, this makes the rigidbody move in GLOBAL z direction. Is there a way how to make Vector3 local? If there isn't way how to do that, can you tell me of another way how to move the rigidbody at a constant speed. Please give an example script in javascript.
Thanks
Answer by Jesse Anders · Jan 23, 2011 at 03:44 PM
You can use Transform.TransformDirection() to transform a vector in local space to world space. If you want the velocity to be parallel to one of the cardinal basis vectors in local space (as is the case in your example), you can use Transform.right, .up, or .forward.
For example, the code you posted would then look like this:
rigidbody.velocity = transform.forward * yourVelocity;
Although in this case 'yourVelocity' would probably be better named 'yourSpeed'.
Superb Bro, It's works for me, you save my at-least 2 hours. thanks a lot.
It says i can't use the multiplication with Vector3s what do I do?