- Home /
Local Direction of Vector3
Hello. I guess my problem doesn't make you hard but I want to get understand rotation of Vector3.
This is my example object. We assume it's in position.Vector3(50,60,70). When I give him rigidbody, and AddForce(Vector3.right) he gonna move in red arrow direction (right direction).Local Right Direction is the same like World Right Direction. Now I'm rotating my object.
When I'll do the same things like above my object will move in purple arrow direction (world space right direction). It's not the same like local right direction. I want to know (but have no idea) how to take right (red) direction in local space of this object - red arrow in 2nd picture.
I don't want link to transform.InverseTransformDirection or something, because I want to understand that stuff... I was trying to do my best with many function but I don't get it. Somebody can help me?
Answer by robertbu · Feb 07, 2014 at 04:51 PM
Rigidbody.AddForce() takes the world direction, Vector3.Right will be the world right, not the right of your object. You can switch to using Rigidbody.AddRelativeForce(), or you can supply AddForce() with world vectors. Transform.Transform.Direction() will convert a local vector to a world vector. In addition, Unity provides some shortcuts for you: transform.right, transform.up and transform.forward. To summerize, to do what you are asking, you can do any of:
Rigidbody.AddRelativeForce(Vector3.right);
Rigidbody.AddForce(transform.right);
Rigidbody.AddForce(transform.TransformDirection(Vector3.right));
Your answer
Follow this Question
Related Questions
Physics2D AddForce Direction Vector Issue 1 Answer
Photon instantiate and addforce to arrow 0 Answers
Make player move in local direction he is turned. 1 Answer
add force in camera direction 1 Answer