Hey guys,
Trying to do something simple but I'm stuck. I have a 2D airplane that I want to rotate when holding down the UP or DOWN keyarrows, and I want it to rotate back to 0 when you release the key. I'm almost there... but rotating back to 0 is the problem, because it never reaches 0. This is the code:
float smooth = 5f;
float tiltAroundZ;
Quaternion target;
if (Input.GetKey(KeyCode.UpArrow))
{
tiltAroundZ = Input.GetAxis("Vertical") * maxUpRotation;
target = Quaternion.Euler(transform.rotation.x, this.transform.rotation.y, tiltAroundZ);
GoUp();
}
else if (Input.GetKey(KeyCode.DownArrow))
{
tiltAroundZ = Input.GetAxis("Vertical") * maxDownRotation;
target = Quaternion.Euler(transform.rotation.x, this.transform.rotation.y, -tiltAroundZ);
GoDown();
}
else
{
target = Quaternion.Euler(transform.rotation.x, this.transform.rotation.y, 0);
this.transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}
Hi, thanks for your answer. Yes... I think that is the problem, it is never reaching the target... which is Zero. I'm not quite sure how to fix that though...
– anon54688491