An Example of RK4 in Games

Take a look at the following game:

http://video.aol.com/video-detail/runge-kutta-video-game/776097806

Runge-Kutta Game

The game consists of a tiny grey rock that is connected to the fireball by a spring. The idea behind the game is that the player controls the tiny grey rock using the mouse and tries to steer the fireball into crashing into the large brown rocks. A differential equation can be obtained using known formulas for the force on a spring, and using the Runge-Kutta method, these formulas can be efficiently computed.

From elementary physics, we know that the formula for force F by a spring with spring constant k and distance from pivot x is

F = -kx2

We also know from Newton’s Second Law of motion, that the force F on any object of mass m, and acceleration a follows the equation

F = ma

Thus we have

ma = -kx2

However, we know that

d2x

Thus we have

d2×2

which can be rearranged to get

x2

Using RK4, this formula can now be efficiently solved to yield a rather accurate value for x, and consequently the new velocity vector that the fireball should be traveling in.

Posted in Topics: Uncategorized

Jump down to leave a comment.

Leave a Comment

You must be logged in to post a comment.



* You can follow any responses to this entry through the RSS 2.0 feed.