Obstacle Course: Rotate an Object - Time.deltaTime?

In the Rotate an Object video of the Complete C# in Unity / Obstacle Course - why do we not use ‘Time.deltaTime’ in the rotation of the ‘spinner’ wall?

1 Like

Hi Rory_B,

That’s a good question. Thank you for asking. Rick applied the example from the Unity API, which does not use Time.deltaTime either in this case. Since most parts of Unity are not open-source, we do not know why Time.deltaTime was not used in the example. Unfortunately, the API does not explain anything in this respect.

Did this answer your question?

See also:

Yes and no.

I see that Time.deltaTime is not specified in the Unity API and it doesn’t explain why.

But this movement would still be effected by and appear differently on computers depending on their specification.

I included Time.deltaTime on a rotAxis variable, then moved it to the Transform parameters -

void Update()
        transform.Rotate(0.0f, rotAxis * Time.deltaTime, 0.0f, Space.Self);

I guess I could ask a new question of the game dev community which would be - is it advisable to include Time.deltaTime on any movement driven by C#?

Not necessarily. It might be that Time.deltaTime is already built into the Rotate method. We do not know how the Rotate method works exactly.

is it advisable to include Time.deltaTime on any movement driven by C#?

By C#, you mean the code you write while using the Unity framework? If so, I would say: Use Time.deltaTime for all movements (and maybe also the rotation) in the Update method.

Actually, Unity recommends to use Rigidbody methods (e.g. MovePosition and MoveRotation) in the FixedUpdate method but you’ll sometimes see them being called in Update in the examples in the API. Unfortunately, the API is relatively inconsistent, so it is difficult to find reliable information. The best would be to simply always test your code in your game and never assume that something works just because somebody claimed it would.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms