0
votes

I am making a mobile car game with unity. I would like to move the needle in the speedometer from 0 position to 180 position; representing the rotation degree of my phone. so i don't need the needle to rotate the whole 360 degrees, I want it to stop when reading reaches 180 degrees. I have tried to get the Z- rotation of the arrow when pointing at 0, and the same for 180 degree, and made a Lerp between them, but the needle rotates a whole circle! I don't want the needle to rotate in both clockwise and anticlockwise direction when pointing at 0, I want it to rotate Clockwise,and vice versa when reach 180 degrees, any help?

1
You can add your code here so anyone can point the mistake or suggest other options to be corrected in your implementation. - Shweta

1 Answers

0
votes

I don't know if this works but it may give you an idea of how it works.

    float angle = speedometer.localEulerAngles.z;
    angle = (angle > 0) ? angle - 180 : angle;
    if (angle >= 0 && angle <= 180)
    {
        speedometer.Rotate(Vector3.forward * 10 * Time.deltaTime);
    }