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?