I have a system of equations that follow Eulerfs approximations. I have tested them out fully and they work with my game to produce truly frame rate independent results. They look as follows:
va = throttle*vdirection;
vp += va*dt + va*dt*t*0.5;
vv += va*dt;
prefix v stands for vector.
I am using the proper vp += va*dt + va*dt*t*0.5; as opposed to partial vp += va*dt; because the program I am making does not have single forces acting for long periods of time; instead, I need to be able to see small forces immediately come into effect. For the same reason, the position is calculated before velocity.
With the above setup, I have varied dt to ensure the game engine runs smoothly regardless of frame rate. The problem is, since I am modeling car behavior, I want there to be resistance on the vehicle. When I go ahead and make the following changes to the code to allow for this, I notice that the system of equations is significantly interrupted enough that it becomes frame based again:
va = throttle*vdirection;
vp += va*dt + va*dt*t*0.5;
vr = -cResist*vv^2*sgn(vv);
vv += va*dt + vr;
As delta_t increases, the velocity fails to return to zero at a fast enough rate (when there is no acceleration present) and the vehicle zooms off into QNAN and recently, INF.
I've tried making the line in question time dependant:
vv += va*dt + vr*dt; //attempt 1
vv += va*dt + vr/dt; //attempt 2
but both of these attempts have utterly failed. I guess what my question is how can I correctly model drag and resistive forces into the Euler approximations I am using so that they maintain their frame rate independent speeds?
++Thanks in advance!
"a low level aho master like you couldn't kill me even if I let you"