Sorry, I'm new to Runge-Kutta calculations, but I'm working on a game and I believe they're what I need to better model deceleration due to drag. Basically, I have an engine producing engineForce, and a counteracting dragForce.
For the sake of argument, I'm using a very simplistic drag equation, where dragForce = (v^2)/2. Previously, I did acceleration like so:
$v = v + (engineForce-dragForce) * dt$
or
$v = v + (engineForce-\frac{v^2}{2}) * dt$
where dt is the timestep in the program. This was leading to instability where velocity would suddenly drop, causing drag to drop, causing velocity to shoot back up, etc. I believe this is due to the timesteps being too large, so something Runge-Kutta could help with. My understanding is that the RK4 equations would be:
$k_1 = (engineForce-\frac{v^2}{2})*dt$
$k_2 = (engineForce-\frac{(v+\frac{k_1}{2})^2}{2})*dt$
$k_3 = (engineForce-\frac{(v+\frac{k_2}{2})^2}{2})*dt$
$k_4 = (engineForce-\frac{(v+k_3)^2}{2})*dt$
And putting it all together for acceleration:
$v = v + \frac{k_1+2*k_2+2*k_3+k_4}{6}$
I tried implementing it but it doesn't seem to work. Can anyone explain what I'm doing wrong?