- Home /
Apply force at an angle or transform.rotation
Wondering if its possible to apply a force at an angle. I have a rigidbody that rotates around a centre point and when its legs hit a trigger I want to add a force at whatever the Z rotation happens to be. For example if the rigidbody's transform.rotation.z is at 248 degrees a force is applied at that angle and the rigidbody travels in that direction. Any help would be greatly appreciated!
Answer by duck · Mar 09, 2010 at 05:11 PM
Yes this is entirely possible. When applying a force, you specify the direction as a vector, and since you have a transform, you also have convenient access to its local "forward", "up" and "right" directions as vectors (and the negative of those gives you the back, down and left directions).
So, all you need to do is this:
rigidbody.AddForce(transform.forward * amount);
(where amount is some value you specify!)
This is great; saved me from a load of headaches, thanks!