Why we dont use time.deltatime?

Hello, i just finished this lesson and was asking me why in this case we dont use time.deltatime for projectile velocity.
i dont know why, but i dont understand yet when i should use it. :flushed:

1 Like

Hi,

Welcome to our community! :slight_smile:

That’s a good and important question. The velocity belongs to the Rigidbody2D class which belongs to the physics simulation. The physics simulation takes care of the framerate-independency. That’s why we must not use Time.deltaTime with Rigidbody2D members.

The Transform object is also part of the physics simulation but if we override its values directly, we circumvent the physics simulation because we do not take any of the other colliders or the gravity, friction and so on into consideration. We just override the position.

Update() gets called once per frame. If we add 1 to the transform.position.x in Update() (simplified explanation!), this would mean that our position value increases by 1 each frame. One frame is not necessarily 1 second long. With a framerate of 60, our game object would get moved 60 WU per second.

And that’s the difference between Transform and Rigidbody2D members. And the reason why we use Time.deltaTime with Transform members but not with Rigidbody2D members.

Did this clear it up for you?


See also:

6 Likes

very helpful, thank you =)

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

Privacy & Terms