# Transform.Rotate and FPS

Hey everybody,

in my current project I stuck a bit at this point:
I’m using transform.rotate to rotate an object which the player must not collide with.
The rotation is in the Update() function which means that you get different speed depending on the framerate.
This is very annoying…
Does anybody have a better way to make the rotation independent from the framerate?

``````public class Rotation : MonoBehaviour
{

public float speed;

private void Start()
{
speed = Random.Range(4, 8);
}

void Update()
{
transform.Rotate(0, speed, 0);
}
}
``````

Thanks!

Multiply speed by Time.deltaTime. That represents the amount of time since last frame. That way it’ll turn proportional to the frame rate, even if it goes up and down.

Edit: Also when you do this, your speed becomes rotation per second, not per frame, so it will be a lot slower than it was before, You will just want to adjust the speed to higher number, accordingly.

1 Like

You should multiply by Time.deltaTime. This makes any value frame-rate independent, or frame-time dependent (choose your perspective).

That is, if you wanted to rotate by 90 degs per second with a varying frame-time, you would not take a fixed value, but you’d take the time it took to complete a frame, and multiply your base value with it.

Example:
If it takes 0.015 seconds, it’ll rotate 0.015s90degs/s = 1.35 degs for that particula frame.
If the subsequent frame takes 0.02 seconds for some reason, it’ll take 0.02s
90 degs/s = 1.8 degs.
And so on…
Sum up all the values, and your rotation will be ~90 degs in approx. 1 sec.

@kdgalla beat me to it

You explained it better, though.

Hey buddies,

that was pretty easy! You helped me a lot
I really appreciate it!