- Home /
Why my rigidbody object doesn't go straight?
I have a box collider and I apply
rigidbody.AddRelativeForce(Vector3.forward*z*velocitSpostamento, ForceMode.Force);
rigidbody.AddRelativeTorque(Vector3.up*x*velocitSpostamento/2000, ForceMode.VelocityChange);
to move it, but instead of going straight, it curves
I'm sorry if my comment sounds silly, but isn't AddRelativeTorque meant to do just that? Turn your object according to physics? If you're turning and pushing forward, a curve is what to expect, no?
Answer by WillTAtl · Dec 04, 2011 at 10:57 PM
gregzo's comment is not silly, he's right. The difference between AddForce and AddRelativeForce is that AddRelativeForce applys relative to the object's rotation, while AddForce uses global directions. AddRelativeTorque is causing the object to spin, so the direction AddRelativeForce is applied in constantly changes along with it.
If you want to keep pushing it one direction while it spins, you'll want to use AddForce instead.
:edit: just realised gregzo and I were both making the assumption you applied this force repeatedly over time, which would result in it following a curving trajectory. It's also possible that it's curving downward because you did not disable gravity for the rigidbody!