Alex Walton
Alex Walton

Reputation: 23

Are Unity Rotations & Torque both measured in degrees of rotation per second?

Are Rotations & Torque both measured in degrees of rotation per second?

I am trying to match the rotation speed of two objects. One is rotating using torque, while one is rotating using a transform. According to the Unity docs and the forum posts I've read, they can both be measured in degrees per second if the transform rotation is multiplied by Time.deltaTime.

Rotate:

The implementation of this method applies a rotation of zAngle degrees around the z axis, xAngle degrees around the x axis, and yAngle degrees around the y axis (in that order).

Add Torque as a VelocityChange:

ForceMode.VelocityChange: Interprets the parameter as a direct angular velocity change (measured in degrees per second), and changes the angular velocity by the value of torque. The effect doesn't depend on the mass of the body and the simulation step length.

I have a GameObject set to rotate at a given speed per second, and a Rigidbody with angular drag set to 0 that is given a torque value. Theoretically, these two objects should be rotating at the same speed:

[SerializeField] private GameObject Object1;
[SerializeField] private Rigidbody Object2;
[SerializeField] float RotationSpeed = 1f;


public void Start()
{
    Object2.AddRelativeTorque(Object2.transform.up * RotationSpeed, ForceMode.VelocityChange);
}

public void Update()
{
    Object1.transform.Rotate(Object1.transform.up * RotationSpeed * Time.deltaTime, Space.Self);
}

However, they rotate at very different speeds. Is there something I'm missing here about how this should work?

Upvotes: 1

Views: 642

Answers (1)

shingo
shingo

Reputation: 27011

I am not sure if the word degrees includes the meaning of degree and radian, but I can confirm that the unit of the torque parameter is radian/second when ForceMode.VelocityChange is given. And the result will be affected by maxAngularVelocity and angularDrag properties.

BTW there is a problem in your code, since you used AddRelativeTorque and Space.Self, you shouldn't use a global vector for the first parameter if you want the object to be rotated along its y axis.

Object2.AddRelativeTorque(Vector3.up * RotationSpeed * Mathf.Deg2Rad, ForceMode.VelocityChange);
Object1.transform.Rotate(Vector3.up * RotationSpeed * Time.deltaTime, Space.Self);

Upvotes: 0

Related Questions