I have an aeroplane controller that can rotate on z and y axes. When the up/down or left/right inputs == 0, I want the plane rotation to reset (become level again).
After some trial and error, this works:
if (Input.GetAxis("Horizontal") == 0.0f && transform.rotation.z != 0f) {
Vector3 tempRotation = new Vector3();
tempRotation.z = 0.0f;
transform.rotation = Quaternion.Euler(tempRotation);
}
However, this immediately snaps into position. I want it to be a gradual rotation. This also affects the camera in a negative way (also snaps).
I tried stuff like tempRotation.z -= 0.1f;
for each update cycle etc, but this doesn't stop when it gets to 0 (and I have no idea why):
if (Input.GetAxis("Horizontal") == 0.0f && transform.rotation.z != 0.0f) {
Vector3 tempRotation = transform.rotation.eulerAngles;
tempRotation.z = (float) Math.Round(tempRot.z, 1);
tempRotation.z += 0.1f;
transform.rotation = Quaternion.Euler(tempRotation);
}
Does anyone have any idea? Thank you.