Game Physics


Hi, I’m Glenn Fiedler and welcome to my series of articles on game physics.

In this series you’ll find information about RK4 integration, the best way to time-step your simulation, rigid body simulation in 3D, spring physics and how to network a physics simulation.

If you find these articles useful, please consider making a small donation to support my writing and help cover hosting costs. Every few years I take time off between game projects to write these articles for you, and that means I don’t get paid to do it!

Thanks!

Glenn Fiedler
gaffer@gaffer.org


Integration Basics

Integration is used to determine the motion of an object over time. In this article I show how to correctly integrate the equations of motion using an RK4 integrator instead of starting off on the wrong foot with a stupid Euler integrator.

Fix Your Timestep!

Even an RK4 integrator is sensitive to the amount of time you step when integrating. Decouple your physics timestep from the display framerate so that your simulation behaves exactly the same way each time it is run.

Physics in 3D

Leap ahead from integrating single values to integrating the entire physics state for a cube in three dimensions. Introduces rotational physics concepts including orientation in 3D, angular velocity and momentum, inertia and torque.

Spring Physics

Explains the physics of springs and how to apply them to control physics simulations. Learn how to implement joints, constraints, motors and basic collision response.

Networked Physics

How do network games synchronize physics over the network? This article explains the core techniques used in today’s first person shooters and shows how you can apply these techniques to network your own physics simulations.

  1. Chaz
    April 4, 2008 at 9:23 pm | #1

    This articles are insightful. Very recommended.

  2. Michael Krause
    July 11, 2008 at 7:57 am | #2

    These articles have been extremely helpful. Thank you very much!

  3. DaveC
    August 22, 2008 at 6:35 am | #3

    These articles are very useful but I can’t find any way to navigate to them from your homepage, none of the links lead to these.

  4. August 22, 2008 at 8:56 am | #4

    Fixed!

  5. Mikhail
    October 15, 2008 at 8:02 am | #5

    Hello Glenn,
    Greetings on that series of articles.
    Any idea how to integrate Coulomb contact friction in
    particle – mesh or particle – particle interaction?

  6. October 15, 2008 at 9:38 am | #6

    hey mikhail, i don’t know how to do that yet – sorry!

  7. Martin
    October 24, 2008 at 4:56 pm | #7

    Great articles. Really helped me out. I find that alot of the documentation for this kind of material is generally written in a style suited to mathematicians which I find difficult to interpret. Thanks!

  8. October 24, 2008 at 6:49 pm | #8

    yeah you and me both, its like they actively try to make it hard to read :)

  9. giggo
    February 27, 2009 at 4:32 pm | #9

    Hey glenn I was wondering, do you know a lot of calculus ? Do you study daily ? I’ve seen most people pick the formulas and general algorithms to make their physics but they usually don’t know what exactly the formulas mean.

    • February 27, 2009 at 9:44 pm | #10

      i’m a self taught programmer, i have no degree but i’ve gone to a few university courses to brush up on some more mathematics – and i did advanced math in highschool, so i have decent background, but really *nothing* on somebody who went through actual physics or electrical engineering maths

      in otherwords, i have “programmer mathematics”, meaning i learn what i need to do what i want to do, and not much more

      so i don’t do calculus daily, just when i need it. and usually, it’s very VERY slow :)

      but a key thing is that i always try to understand, as deep as i can what i am working on… so I do know the taylor’s theorem basis for RK4 and understand it, and i can derive it if necessary. the only thing i’m a bit fuzzy on in the whole physics articles is how to calculate the spin quaternion to integrate the orientation from angular velocity. i don’t fully understand the mathematics behind that, but the rest i’m pretty solid on.

      if you want to study something to get a deeper meaning of the physics equations, i highly recommend taking a look at baraff’s siggraph courses on physics simulation (google for it) – this is a good place to get a good understanding of the mathematics and ideas behind physics simulation

      in fact really, you could just look at my articles as a poor man’s version of his papers, covering much the same material, but with a programmer focus instead of a mathematics focus

      cheers

  10. October 11, 2009 at 6:46 am | #11

    Hi Glen. I am loving the articles you’ve written so far. They’re very informative and have given me some great ideas for building my own physics engine. I was wondering if you have any plans to write an article about collision detection (or if you’ve already written one).

    Thanks again!

    • October 11, 2009 at 6:59 pm | #12

      Hello James, well I was going to write one about collision detection, but then I found out about “Real Time Collision Detection” by Christer Ericson. This is *the* book you want to get. Any article I would write would just be inferior to this.

      cheers mate

      • October 12, 2009 at 9:15 am | #13

        Thanks Glenn, It looks pretty good. I’ll give it a read,

        James

  11. scragar
    October 14, 2009 at 5:51 pm | #14

    On the spring physics page there’s a link tag around the text “next article” but it’s not linked to anything.

  12. dynamically challenged
    November 11, 2009 at 6:03 pm | #16

    Thanks for being so generous with the source code AND dynamics simulation explanations. I’ve tried using your example code to model a real dynamic system and run into the dreaded divergence ‘explosion’. Even though the dynamics are ‘low’ and the 100hz timestep should be plenty small enough (I think), it’s not easy sorting out the cause.. Any suggestions for diagnosing this general type of problem? Is there a general series of diagnostic steps that you’d recommend for resolving divergence? (I started by cutting the timestep down by a factor of 10 but it just pushed the divergence further out in time). Since everything is done as a float is there a potential for things to become denormalized/inconsistent that requires frequent action?

    • November 11, 2009 at 6:55 pm | #17

      I really cannot comment without knowing more details about your simulation, what exactly are you trying to do?

      • dynamically challenged
        November 12, 2009 at 4:50 pm | #18

        I’m trying to simulate simple drifting of an object in a water flow. So, I start with a stationary object and expect it to speed up and reach steady state at the same speed as the current. It seems to do this but after reaching steady state, an oscillation develops that eventually diverges. I noticed that after a couple uses of coordinate transformations using quaternions, some of the x,y forces bleed into the z axis (which is a no-no for my 3dof sim). Do I need to normalize occasionally or take some action to prevent angular momentum from being developed somehow? The cube demo seems to have an angular velocity damping term added to prevent this from being a problem.. is it necessary because of precision issues with the implementation? Thanks for the discussion.

  13. November 12, 2009 at 4:53 pm | #19

    it is generally necessary to renormalize the quaternion after you integrate it, provided that it is a certain distance from length 1.0, this may help.