Velocity integration in 8direction behavior is inconsistant with differing framrates. Maybe others 2

0 favourites
  • 7 posts
From the Asset Store
This is a simple login feature to access Metamask in construct 3. Requires a Chrome Browser and Metamask Extension.
  • Have you ever had jump height, or other abilities seemingly feeling different when framerate differs? Even while using dt correctly?

    When using Euler integration, constant acceleration of an object can result in differences in in object position over time based on the frame rate. This is undesirable.

    Put in simpler terms, the method that the 8direction behavior uses to calculate the objects new position depends on the frame rate.

    Let v = velocity and p = position.

    Euler integration method:

    //calculate acceleration * dt

    v += Acceleration;

    p += v * dt;

    Using the above method, if we accelerate constantly over some time period, the higher the dt value, the further we we get. The more steps we have (the lower the dt value and higher frame rate), we will get a more accurate final position. In order to compensate for the errors in Euler integration (which works fine where times doesn't fluctuate), we should use the method below:

    //calculate desired acceleration * dt, then split in two parts:

    a1 = Acceleration * 0.5;

    a2 = Acceleration - a1;

    v += a1;

    p += v * dt;

    v += a2;

    This second method applies half the acceleration this frame and the remainder after position has been updated, meaning it won't affect the object until next frame. You can plot out the math. Or I'll update with a website link explaining it. EDIT: openarena.ws/board/index.php

    Anybody else use the above method to smooth out acceleration, gravity, or other forces?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Looks like that method is called leapfrog integration. It averages out changes to acceleration from frame to frame.

    Most behaviors use velocity verlet integration. Which handles constant acceleration motion perfectly no matter the timestep.

    When acceleration changes from frame to frame I don’t think there’s a silver bullet integration method to make it frame rate independent.

  • Looks like that method is called leapfrog integration. It averages out changes to acceleration from frame to frame.

    Most behaviors use velocity verlet integration. Which handles constant acceleration motion perfectly no matter the timestep.

    verlet is appropriate for springs and the like, correct?

    I remember learning about the one I mentioned in order to correct maximum jump height in games running at different frame rates. I had the issue with my platformer behaviors having drastically different maximum jump heights at 30fps and 60fps

  • The verlet you’re thinking of is slightly different. It infers velocity from position change which does work well for ropes and cloth.

    Anyways it’s something you can test either way.

  • I found a link to some images and simple explanation for those interested:

    openarena.ws/board/index.php

    As for the Velocity Verlet Integration, I can seemingly only find info on the version that infers velocity from current position and last position. I didn't know there was another, can you point me to it?

    I think I know of Explicit Euler (and semi-version), Midpoint, vk4, The german named one lol... something like rungakatta?, and Verlet (velocity infered by position)

  • It’s on Wikipedia.

  • Some tests of different physics integration methods with different timesteps. I included the platform behavior too to compare, but it just uses whatever dt currently is. It draws a nice graph to compare time vs y. The speed of the jump has to do with the timestep used, so it can be ignored.

    https://www.dropbox.com/scl/fi/sluu3khqb1b0vzw5de0lu/integrationTests.capx?rlkey=0jjkfkcaww1evb03bs4fj9mpu&dl=0

    The results show that leapfrog, velocity verlet, and the platform behavior in c3 all have matching curves.

    You could do similar tests for the 8dir behavior vs an event based one.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)