Handmade Hero»Forums»Code
The_8th_mage
69 posts / 1 project
High tech integration methods
i saw in stream 43 that casey used a regular integration method, something like
p'=1/2*a*t^2+vt+p
in the past, i saw an article which said that using that integration method is not great, and you should use something like runge-kute or vervet method, or something simple like averaging the velocities between start and end. is casie saving it for future episodes or he just doesn't think it's significant?
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
High tech integration methods
Those are numerical integration techniques, not analytical integration techniques. You always use analytic functions if you have them, because they're perfect. You only use Runge-Kutta or Verlet schemes when you have to do numerical integration, which is not perfect.

Since we're not trying to do physical simulation, we may never have to do numerical integration, and may always be able to do perfect integration, which is always strictly superior because it has literally no error besides bit rounding.

- Casey
Benjamin Kloster
48 posts
High tech integration methods
Edited by Benjamin Kloster on
Methods like Runge-Kutta or Verlet are for solving differential equations. In the case of the motion equations, they aren't necessary, unless the acceleration depends not only on the time, but also on the current position (force field) and / or velocity (drag).

Even then, you could get away with using simple integration if the force field's strength or direction doesn't vary too much over the length dt * v(t), where dt is the current time step. In this case, you can just assume a to be constant and integration becomes trivial. Similarly for drag.
The_8th_mage
69 posts / 1 project
High tech integration methods
What about collision detection? That's a force field which vary significantly in vdt, anyway, i think that euler is bad even for forces that doesn't vary significantly.
Benjamin Kloster
48 posts
High tech integration methods
Yes, force-based collision resolution is one of the cases where it can be necessary to resort to numerical integration. But, especially in 2D games with simple collision hulls, collision resolution can often be done exactly with impulse reflection instead of applying forces.
The_8th_mage
69 posts / 1 project
High tech integration methods
Collision reflection is like an infinite force, thats why i think you should use those methods. I think that even a 2D game, has to use an elaborate way to handle collisions, to avoid framerate dependence and speed dependence and what's not.