I know there are other questions about the difference between these two things. But I haven’t found anything regarding time.
As we all should know, if you call transform.Rotate and give an angle without scaling it using Time.deltaTime, the object rotates at insane speeds. I wanted to be able to clamp the angle of the rotation between 180 and -180. So I decided to add/subtract the rotationRate from a “currentAngle”, and then assign that rotation using a Quaternion. To my surprise, I did not need to scale the rotationRate with time to get my desired result. Anyone have any insight to this?
public class RotateCannon : MonoBehaviour
{
public float rotationRate = 30f;
float currentAngle = 0f;
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
currentAngle -= rotationRate;
else if (Input.GetKey(KeyCode.RightArrow))
currentAngle += rotationRate;
transform.localRotation = Quaternion.Euler(0, 0, currentAngle);
}
}