Home > Back-end >  Unity: AddTorque() causes object to change its rotation axis
Unity: AddTorque() causes object to change its rotation axis

Time:08-19

I'm not sure how to exactly describe this issue. I'm rotating an object using AddTorque(), but the object immediately begins to change the axis around which it rotates (or it at least looks like so). Best check this gif to see what I mean: https://gfycat.com/hatefulbadandeancat

The code I have is this:

rigidbody.AddTorque(player.transform.up * -inputX * rotationForce * Time.fixedDeltaTime);

Perhaps this is not an issue at all, but an expected behaviour. However, I would rather have this object rotate constantly just as it does at the very beginning and not change its rotation axis.

I tried using AddRelativeTorque() instead of AddTorque(), but then I couldn't get the object to rotate the way I wanted it to.

CodePudding user response:

The simplest solution is probably to restrict rotation in the inspector and allow it to rotate on only one axis.

CodePudding user response:

Try use Vector3.up instead of transform.up if it helps your situation. But remember to align the object first

  • Related