# Change speed of rotation (magnitude) without changing direction (sign)

I have this code that rotates my object:

      private void FixedUpdate()
{
transform.Rotate(0, 0, Speed * Time.deltaTime);
Debug.Log(Speed);
}



When I call this function, I want the object to start rotating in the opposite direction (this works):

        public void changeDir()
{
Speed = -Speed;
}


When I call these functions, I want to change the speed of rotation, while keeping the direction (clockwise or counterclockwise) the same. But these always make the object rotate to the right instead of left:

        public void ZoomSpeed()
{
Speed = 330f;
}

public void ZoomNormal()
{
Speed = 125f;
}


How do I maintain the same direction (sign) when changing the rotation speed?

• Could you show us, from where you are calling changeDir()? Mar 15 at 12:13

I'm guessing you might be looking for something like this?

public void ZoomSpeed()
{
Speed = 330f * Mathf.Sign(Speed);
}

public void ZoomNormal()
{
Speed = 125f * Mathf.Sign(Speed);
}


That is, you want to change the magnitude of the Speed variable, while keeping its sign? (So if Speed was less than zero before calling ZoomSpeed(), it will be -300 afterward, instead of +300?)

• THANK YOU THANK YOU!!! Mar 15 at 13:22