How do I stop my object from over rotating after key is lifted?

const float RotateDegreesPerSecond = 150;

void Update()

{
    float thrusterInput = Input.GetAxis("Thrusters");
    float rotationInput = Input.GetAxis("Horizontal");
    
    //if (thrusterInput > 0)
    //{
        //float rotation = rigidBody2D.rotation;

        //print(rotation);
       // print("space");
    //}

    float rotationAmount = RotateDegreesPerSecond * Time.deltaTime;

    if (rotationInput < 0)
    {
       transform.Rotate (Vector3.forward, rotationAmount);
       print("rotate1");
    }
    else if (rotationInput > 0)
    {
        rotationAmount *= -1;
        transform.Rotate(Vector3.forward, rotationAmount);

        print("rotate2");
    }

    
}

Hi, The question doesn’t clearly say what is it that you want to achieve ? What key? Please reframe to get accurate answers.

Hello,

The reason seems to be not checking when the input is 0, that is key not pressed or lifted

You may try with below 3 options, the 3rd one will be better and cleaner

// Option 1 - add to the existing code
else if (rotationInput > 0)
{
      rotationAmount *= 0;
      transform.Rotate(Vector3.forward, rotationAmount);
      print("rotate3");
}

//Option 2 - add to the existing code
else
{
      rotationAmount *= 0;
      transform.Rotate(Vector3.forward, rotationAmount);
      print("rotate3");
}

//Option 3 and better option - replace code with below
 const float RotateDegreesPerSecond = 150;
 void Update()
 {
     float thrusterInput = Input.GetAxis("Thrusters");
     float rotationInput = Input.GetAxis("Horizontal");
     
     float rotationAmount = RotateDegreesPerSecond * rotationInput * Time.deltaTime;
     transform.Rotate(Vector3.forward, rotationAmount);
 }