All Questions

Community

C
FABRICE CIPOLLA
posted to: Adding gravity

Is delta really needed?

I have 2 questions about the need of the delta:

1) As the "move_and_slide" function already apply the delta to the velocity. What is the interest to apply the delta to the gravity (who will only affect the velocity)?

2) Even without the 1, the physic_process has a fixed delta, is-it not useless to multiply the gravity by a fixed value?

Thanks!

  • Nathan Lovato replied
    Hi! Good questions. This is due to gravity not being a speed, but an acceleration. Let's replace gravity, velocity, etc. by their units and make the calculations there. velocity is in pixels * seconds, it's a speed (oriented in a given direction) gravity is in pixels * seconds ^ 2, because it represents an acceleration The motion applied by move_and_slide on the screen on a given frame is in pixels We cannot add or subtract values with different units. So to add the effect of our gravity on the velocity, we need to convert it so the units match that of the velocity. That's why we do velocity.y += gravity * delta, delta being in seconds. From the units' standpoint: pixels / seconds ^ 2 * seconds = pixels / seconds
  • Nathan Lovato replied
    2) physic_process has a fixed delta, is-it not useless to multiply the gravity by a fixed value? It is a fixed value in seconds, so it's important for our units as shown above. Then, this fixed value isn't arbitrary. It could change from project to project. It's your physics step value, the amount of time you want to advance the physics simulation on every frame. Generally, it is 1 / framerate, but you can control this with the Physics FPS setting in the Project Settings.
  • Nathan Lovato replied
    The formatting seems to be lost when I reply to questions, sorry for that! I'll send the team a message so they can fix this.
  • K
    Uncle Khan replied

    Yes. Formatting is lost on questions posted as well.