Introduction

This is a simple demo of the implementation of and differences between a Forward Euler Method (FEM) integrator and a Velocity Verlet integrator for simple projectile motion.  It also includes a demo of how to implement a changeable acceleration such as from first-order wind resistance.

How to Use

You can change the value of the initial velocity and launch angle, although I've found that 25 m/s at an angle of 60 deg fills the screen nicely and allows for easy differentiation between the FEM and Velocity Verlet methods.

You can also change the time interval between physics calculations.  By default, this is set at Unity's default value for Time.fixedDeltaTime of 0.02 sec.  Making this delta time smaller will result in a more accurate result, whereas using a larger value will amplify the differences in the error rates of the two integration methods.

The Mathematics of Integration Methods

All methods for integrating the equations of motion stem from the two fundamental relationships that define velocity and acceleration with respect to position and time.  If we think of the position of the object generically as, r, and time as t, we can define the quantities of velocity and acceleration as follows:

v = dr / dt

a = d2r / dt2 = dv / dt.

Velocity is the first derivative of position with respect to time and acceleration is the second derivative of position with respect to time.  Acceleration is also the time derivative of velocity.  This formal calculus-driven definition is useful for analytical work, but we need an approximation using finite differences that we can use when performing calculations within our computer code.  Instead of thinking of the infinitesimal intervals of a derivative, we will instead think of the finite differences in position, velocity, and time between successive physics frames,

v = Δr / Δt

a = Δv / Δt.

While most integration methods utilize calculus-driven derivations quite heavily, we will minimize our use of that here.  For a more detailed and formal mathematical derivation of the methods we're about to use, see the links provided below.

I provide a broader explanation of kinematics and of the integration methods used in this demo in our evolving textbook on the Mathematics and Physics for Games.

For this demo, we use the Forward Euler Method (FEM) and the Velocity Verlet method.  More advanced integration methods, like the fourth-order Runge-Kutta method (RK4) are more precise, but they are also computationally more expensive.  This is fine if you're performing a physics simulation that can run for a few hours before giving you a result, but in game physics, we need a result in 0.02 seconds or faster!  FEM is very simple, very fast, but can also be very inaccurate.  Velocity Verlet is slightly more computationally expensive, but is significantly more accurate.  In fact, when the acceleration is constant, Velocity Verlet offers the precise analytic solution.  This is why you see this integration method used more now than the simpler, cheaper FEM.

I have an artillery game, Pytillery, that uses the Velocity Verlet method that you can download and inspect the source code to see how this method is implemented in a real project, https://xorpheous.itch.io/pytillery.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Download

Download
IntegratingMotion_PC-BUILD_v1-1-1.zip 19 MB

Leave a comment

Log in with itch.io to leave a comment.