# Easing rotation based on angles, not speed

I am trying to make a simple speedometer / revolution counter, in which the needle eases out at certain positions after acceleration.

I can get it to accelerate nicely by just adding Time.deltaTime to itself like this:

``````IEnumerator StartAcceleration(Positions toPosition)
{
float currentRotation = needleHub.transform.rotation.z;
float originalRotation = needleHub.transform.rotation.z;
float toRotation = resultRotations[toPosition].z - 0.075f

float velocity = 0;
while (currentRotation > toRotation)
{
velocity += Time.deltaTime * 10f;
// Not working
//needleHub.transform.Rotate (0, 0, Mathf.SmoothStep(originalRotation, toRotation, velocity));
needleHub.transform.Rotate (0, 0, velocity);

currentRotation = needleHub.transform.rotation.z;
yield return new WaitForEndOfFrame();
}
``````

I think this is right. It looks right anyway.

The only problem is that all examples on easing rotation I find are based on time, from 0 to 1, where smoothstep, slerps and dampangles are based on this.

But I cannot use time, since I don’t know if the needle has to go from 0mph to 80mph or 0mph to 40mph. If I used time, the speed of the needle would not be the same.

So how do I smooth based on the angle in resultRotations[toPosition]?

Regards.

I’m a bit confused about what is driving what here. But when I do these things, I first define something that goes from 0 to 1. It might be the current velocity divided by the maximum velocity, it might be a timer with current time over total time. To get it to ease, I use an easing function.

With an easing function you map this 0 to 1 value through a curve. Sine between 0 and PI/2 works well for a lot of easing. X^Y is my second most popular curve for my easing. So if you were using a timer, velocity becomes (untested):

``````velocity = Mathf.Sin(Mathf.PI / 2.0f * curTimer/totalTime) * maxVelocity;
``````