Live data from Hacker News

Doing Game Gravity Right

niksula.hut.fi

21–30 of 86 posts

Re: Doing Game Gravity Right

#21
post #18

Earlier quoted context omitted.

All games have minimum requirements.

Yeah, in the perfect world all your buyers will have them. In real life sometimes don't. Plus there is a lot of things you don't know; maybe he haves the minimum requirements but he is running a lot of background process because he installed a bunch of things he doesn't use.

If the game is so bogged down that the fixed timestep cycle is slowing down the game is broken for so many other reasons. Objects will start tunneling through other objects.

Re: Doing Game Gravity Right

#23

you are still doing it wrong. dt should not be affected by framerate. http://gafferongames.com/game-physics/fix-your-timestep/ use an accumulator to have a fixed dt no matter the framerate. With a variable step size you risk all kinds of weird bugs linked to the hard to debug rendering context. The size of dt should be consider a system parameter, tuned for your game and fixed in concrete .

So what happens when the OS doesn't return to your process in dt time?

The whole point of dt is to deal with variable framerate.

Re: Doing Game Gravity Right

#24
post #13

This is still Euler integration, which has poor accuracy whenever the derivative varies with time. The standard numerical integration method is 4th order Runge Kutta. RK4 is also popular for solving many forms of differential equations. A good summary is here: http://gafferongames.com/game-physics/integration-basics/

Correct me if I'm wrong, there is no reason to numerically integrate this. This is not a differential equation. The integral solution is a simple function that can just be evaluated.

Re: Doing Game Gravity Right

#25
post #22

What id don't understand is, wouldn't this be only half more correct? I'm not really sure if my question makes sense.

It isn't that they cut the interval by half. It happens that for constant acceleration, this midpoint happens to lay on the actual solution. Notice that there is only one summing of position, and two of velocity.

Re: Doing Game Gravity Right

#26
His improved graph actually still doesn't hit the peak at all frame rates. The right way to do things from the usability perspective would be the calculate the peak and make sure the player can hit exactly that at some point. Otherwise areas that are supposed to be reachable may not be, as he says. The code for that wold be a lot more complex, though, so it may be the wrong thing from a business perspective, spending large amounts of your dev time on a small edge case of users and user situations.

Re: Doing Game Gravity Right

#27
post #3

TIL that I have been doing acceleration calculation all wrong over the years. Thanks for the insight.

I'm a gamedev and I actually use this as in interview question. Getting people to understand this distinction is the difference between pass and fail.

Re: Doing Game Gravity Right

#29
post #20

Udacity has a course, "Differential Equations in Action", that's about numerical solutions of equations of motion and other differential equations from physics, biology, and so on. http://www.udacity.com/overview/Course/cs222/CourseRev/1

I'm between doing that course or doing this one: http://ocw.mit.edu/courses/mathematics/18-03sc-differential-...

Anyone has any insight into the strenghts and weaknesses of each one? I've been unable to find any comprehensive review online about them. I don't have time to do both simultaneously, but can do one first and the other later or alternate between them.

I don't have a strong calculus background though I'm above the average "programmer" or compsci graduate. I'm interested in simulation and numerical problems (specially finite element method) but theoretical background is welcome when its not overwhelming (i.e. when its there for you to understand but its not the focus of the course).

Re: Doing Game Gravity Right

#30
This same thing is used in molecular dynamics simulations. For instance, there is an algorithm called RESPA that is used to break integrations of different types of particle interactions into appropriate timestep intervals. Bond vibrations must be calculated much more frequently than non-bonded interactions.

The algorithm (reversible RESPA) is formally derived from the Liouville operator (which governs the time evolution of any property):

    A(t) = exp(iLt) * A(0)
For instance, A(t) can be position or momentum. The Liouville operator must be symmetric in order to generate a reversible numerical integration algorithm.

The result of all this is basically that:

    p(t + ∆t/2) = p(t) + ∆t/2 F(r(t))
    r(t + ∆t) = r(t) + ∆t p(t + ∆t/2)
    p(t + ∆t) = p(t + ∆t/2) + ∆t/2 F(r, t + ∆t)
where p is momentum, r is position, and F is force.
Post reply on HN