I'm getting really discouraged because I can't seem to figure how how to rotate my object via Rigidbody.AddTorque like it is on a figurative global turn table rather than a local turn table. Another way of describing it is that I want to c calculate a torque vector that will rotate the object's yaw and keep it upright regardless of its pitch without rolling it around. This is a problem for me because I want my player to remain upright without ending upside down because they were pitched and decided to turn.

Someone else had posted about the same problem on a different forum but he didn't receive much in the line of help, however he did provide this really helpful image describing the problem:

Local vs Global

Notice how the left object is tilted and then rotating with respect to its own local coordinates but the one on the right is rotating with respect to the global coordinates instead of rolling around like the one on the left.

How can I achieve this? Is there something obvious I am overlooking or forgetting? Am I explaining it right?


In the following image the top half illustrates what I want while the bottom half is showing what is actually happening. What I want is to be able to tilt the player's pitch and have them be able to rotate almost like a turret. I was able to accomplish this for demonstration purposes by first rotating the player and then pitching. Instead what I am getting is if the player tilts their pitch and then turns they start to bank, or in other words they start to roll.

enter image description here

My code looks something like this:

        _rigidBody.AddTorque(Vector3.up * _horizontal *
            RotateImpulse * Time.fixedDeltaTime, ForceMode.Impulse);

        _rigidBody.AddTorque(Vector3.right * _vertical *
            RotateImpulse * Time.fixedDeltaTime, ForceMode.Impulse);

I sincerely appreciate you all offering to help me with this.

  • \$\begingroup\$ Hmm, that's odd. You should be getting wordspace by default. Can you show us the code you're using, so we can spot if anything is out of place there? \$\endgroup\$ – DMGregory Sep 16 '19 at 1:16
  • \$\begingroup\$ If you want to rotate the modal around global Y via Rigidbody you could use angularVelocity property directly, something lilke rigidbody.angularVelocity = Vector3.up * speed; get your job done \$\endgroup\$ – Digvijaysinh Gohil Sep 16 '19 at 10:31

You can do it by accessing the angularVelocity directly as i commented earlier, however if you want to use the addTorque() you could use something like

rigidbody.AddTorque(Vector3.up * speed, ForceMode.Acceleration);
// or
rigidbody.AddTorque(Vector3.up * speed, ForceMode.VelocityChange);

Notice the second parameter, Acceleration and VelocityChange both applies the torque and ignores the mass of the object, only difference is Acceleration continuously applies the torque while VelocityChange instantly change the velocity,

Or you can use Force or Impulse which are similar to Acceleration and VelocityChange respectively, but consider the Mass in the calculation,

While using any of these two force modes if your object is not scaled evenly in all 3 axis then you will get weird rotation because of the Mass of the object.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.