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:
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?
EDIT:
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.
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.
Rigidbody
you could useangularVelocity
property directly, something lilkerigidbody.angularVelocity = Vector3.up * speed;
get your job done \$\endgroup\$ – Digvijaysinh Gohil Sep 16 '19 at 10:31