I am making a speed meter of car. Its pretty simple when ever speed increases or decreases the meter pin moves accordingly. I have done the movement part of pin but I am unable to get a smooth movement.
public Image meterPin;
const float maxPinAngle = -116f;
const float minPinAngle = 16f;
float meterMinSpeed = 10f;
float meterMaxSpeed = 210f;
void Update()
{
changeMeterSpeed();
}
void changeMeterSpeed()
{
meterMinSpeed = userSpeed;
meterMinSpeed = Mathf.Clamp(meterMinSpeed, 0f, meterMaxSpeed);
meterPin.transform.eulerAngles = new Vector3(0, 0, getTransformRotation());
}
float getTransformRotation()
{
float totalAngle = minPinAngle - maxPinAngle;
float speedNormalized = meterMinSpeed / meterMaxSpeed;
return minPinAngle - speedNormalized * totalAngle;
}
The userSpeed
value is calculated in another function in this script. The only issue is that the movement is not smooth. Any ideas if I can fix the smoothness issue in this script.
EDIT:
Here is a gif to explain whats happening.
Thanks
getTransformRotation()
toTime.deltaTime
? \$\endgroup\$