Here is a technical demo on which I spent a few hours.
It was originally inspired by Kikito's thread: Interesting article about gravity in games.
The purpose of this demo, at last when I started it, was to:
- show various ways to mimic real physics for entitites motion in games without using a dedicated physics third-party library. The motion would include linear motion, and jump as well.
- Study/compare and benchmarks various time - integration methods (in the case of constant acceleration), and how they perform compared to real integration they all try to approximate, with regards to the framerate.
In this demo, you can move those 6 different entities with directional arrows.
You aso make them jump with space key. You can also cap down/cap up the framerate (between preset bounds, 300 and 3 fps) and see the incidence on the entities jump curve. And compare them aswell as opposed to the real integration curve.
Important note: You can hide/unhide an entity and its time-integration method results by clicking on the corresponding rectangle on the legend (upper right).
I have included six different time-integration methods, which are Implicit Euler, Explicit Euler, Improved Euler, Heun, 4th-order Runge Kutta and Verlet (aka Leapfrog).
The simple physical model I set has some constraints: velocity is clamped to a maximum absolute value (per-component). It also takes into account the mass, but actually, all agents have a unit-mass.
Ground friction is included too, but there is no air friction, so that the jump curve remains parabolic.
Some statistics are evaluated and displayed such as the actual acceleration and velocity for each entity, the jump height, range, and the accuracy of the approximation with respect to the real integration method. You can compare them and conclude on which method have the best results according to the framerate.
Source code is Mit-Licensed, and hosted at github.
Love file attached.
Feel free to try, and give your opinion, suggestions.
Thanks in advance.