# How to rotate object until 'if statement' become true

HI! I have an object ‘A’ and when I rotate it up, a float variable ‘B’ increase, when I rotate down the ‘B’ decrease. I have an other float variable ‘C’. My goal is:

``````if ( C > B)
{
Rotate 'A' up
}
if (C < B)
{
Rotate 'A' down
}
``````

The problem is with simple transform.Rotate, it generate a constant shaking, because the rotation overshoot the target, so it start to rotate in the opposite direction, and it overshoot again and so on.

I tried it with RotateTowards method, but it returns the same shaking.

I would like to stop the rotation when B == C and start to rotate when C is increase or decrease. How may I do that?

Hello.

The first probelm i see is that B is a float, so is almost impossible to make B = C, because 4,99999999 is not 5.

the second thing is you should do elise if (not 2 if)

``````if(...)
else if (....)
``````

Then, i dont understand “rotation overshoot the target” is Rotation og object A related with B or C? because you dont explain that.

a function like you do should work it they are not related.

``````void RotateObject()
{
if ( C > B)
{
transform.Rotate(0.2f, 0, 0)
}
else if (C < B)
{
transform.Rotate(-0.2f, 0, 0)
}
}
``````

Bye!

Hello @tormentoarmagedoom!