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?
Thanks in advance!
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!
Thanks for your reply!
A is related with B! B change its value with the rotation of A.
C is a constant value.
Overshoot the target, I mean, for example:
C = 1.3f
B = 0.5f
so A start to rotate up and B is increasing. But the rotation does not stop in time, and B is finish a little bit bigger than C, for example B= 1.35f, and then A start to rotate down, 'cause now C