- Home /
AddForceAtPosition Direction Relative To Parent?
Hey there :)
How do you change the direction of which the force comes from with AddForcePosition, and make it relative to the parent?
Here's the sample of code im using:
rigid.AddForceAtPosition(Vector3(0,0,100), transform.position);
This adds the force in the correct position, however it moves the object in a global direction on the Z plane.
I want the force to always move in the direction the rigidbody is facing.
I feel this could be done by taking away the rotation of the object from the force vector. But I cant get my head around it! :/
Thanks for your time, Magnus :D
Comment
Best Answer
Answer by robertbu · Aug 23, 2013 at 05:27 PM
If you want a direction relative to the parent, use Transform.TransformDirection();
var direction = transform.parent.TransformDirection(Vector3(0,0,100));
This takes the Vector3 in local space and transforms it into global space.