# Help making a car speedometer

I have made a car, but trying to make the Speedometer and RPM gauges are causing some issues. Either the gauge will spin in circles, like a 360 degree angle and not stop at bottom, like a normal car speedometer, or stops at the bottom but will not go back round to start point.

#### Any help appreciated!

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Guaged : MonoBehaviour
{
public GameObject Dial;
private float rot; //Rotation to be added
private float crot; //Current rotation on Z axis
public float xAngle, yAngle, zAngle;
public bool type;

void Update()
{
if (type) //Speedometer MPH
{
rot = CarController.Speed / 130;
crot = Dial.transform.localRotation.z;
yAngle = Dial.transform.localRotation.y;
xAngle = Dial.transform.localRotation.x;
zAngle = crot + rot;

if (crot > 0)
{
crot = 0;
Dial.transform.Rotate(0, 0, 0);
zAngle = 0;
}

Dial.transform.Rotate(0, 0, -zAngle);
}

if (type == false) //Speedometer RPM
{
rot = CarController.Revs / 5000;  //Max Revs is 5000
crot = Dial.transform.localRotation.z;
yAngle = Dial.transform.localRotation.y;
xAngle = Dial.transform.localRotation.x;
zAngle = crot + rot;

if (crot > 0)
{
crot = 0;
Dial.transform.Rotate(0, 0, 0);
zAngle = 0;
}

Dial.transform.Rotate(0, 0, -zAngle);

}
}
}
``````

Using `transform.Rotate()` will rotate it relative to the current rotation.
This means, if your code calculated that at some speed it should have an angle of 30°, instead of tilting it to 30°, it will rotate it 30°s more each `Update()`.

You’ll want to directly set the `transform.rotation`, or `transform.localrotation`, but you won’t have any easing doing so.
You can use `transform.eulerAngles` or `transform.localEulerAngles` to have a convenient XYZ rotation coordinates instead of quaternions. (or use `transform.rotation` and `Quaternion.Euler(x,y,z)` if you prefer)

Since I can see you divide your speed by what I infer is the max speed (130 ?)
You’ll always get a value between 0 and 1.
This means you can use `Mathf.LerpAngle( not_moving_angle, max_speed_angle, yourCalculated_zero_to_one_Value)` to get the angle you should have between a minimum and maximum arbitrary angle. (If you don’t want the gauge to move along the full 360 degrees, like in real cars)