Game-physics for beginners, part ii: Motion under an external force

March 11, 2010

game-physics-logo_rotl_smallThis second tutorial introduces the basics of modelling motion under the influence of an external force by using acceleration. It then goes on to give an outlook on how the connection between acceleration, velocity and position forms a route to animation.

Motion under the influence of an external force

In this tutorial, we want to continue modelling the one-dimensional motion of a ball. But this time, we want to use a more physical approach.

Taking into account external forces by using acceleration

As emphasized in part i, the one thing that really influences the motion of an object are forces! Consider for example gravity, causing objects to fall.

Hence to model the motion of an object, we need to take into account these forces. But these forces are external, hence not object-immanent. So how do we model their impact on the motion of the object?

Well, again from part i, recall: Forces give rise to accelerations (N2). In other words, the external forces acting on the object cause changes in its acceleration.

Now to model the motion of the object under the influence of these external forces in our game, we first of all introduce an object-immanent property a that describes the acceleration of the object. In the notation we are going to use this is:

object.a;

Example 1 revisited: How you do want to do it

Lets return to our example of a ball  moving horizontally in a straight line at uniform speed in free space. In this case, there are no external forces present and hence the acceleration of the ball is equal to zero:

ball.a_x = 0;

Here’s what it could look like: Particle moving from left to right in free space.

Note that for this simple example, the resulting animation is exactly the same as it was before (when we just altered position). So far, so well!

Example 2: Gravity

Now lets consider another example, this time involving an external force: Gravity. Imagine holding up a ball in your hand and letting it go. It will fall down in a straight line. Now if you look very closely, you will notice that it does not fall at a constant speed, but accelerates. Hence the ball’s speed constantly increases.

Here’s what it could look like: Particle falling downwards under gravity.

So how can we model that? Well, simply calculate the force that is acting on the ball and relate it to the acceleration of the ball via (N2). That is:

  • Calculate the force due to gravity acting on the ball. Near the surface of the Earth this simply is

Fg = m * g

where g = 9.81 m/s² is the acceleration due to gravity.

  • Relate this force to the acceleration of the ball via (N2):

F = m * a

  • Work out the acceleration of the ball:

ball.a_y = g

Hence under the influence of gravity, the acceleration of the ball will be g, where g is a constant that we have to declare somewhere in our program.

Connection between acceleration, velocity and position (the route to animation)

So far we have a ball with an object-immanent property that describes its acceleration under the influence of a force, e.g. gravity.

But what does all this have to do with animating motion? After all, we want to see something moving on our screen – like in the example-files – rather than just discussing abstract concepts! Well, bear with me for some more steps.

Starting from the acceleration a of the ball, a technique called numerical integration can be utilised to calculate the velocity v and finally the position r of the ball:

a   →   v   →   r     (Numerical Integration)

Hence this technique enables us to finally animate the objects motion on our screen using the calculated value for r in each frame. But this will be discussed in part iii.

Summary part ii

In this part of the tutorial:

  • We started to work on a way of modelling the motion of an object by using its acceleration, thereby taking into account the forces that act upon it.
  • We saw how to calculate an objects acceleration from an external force, namely gravity.
  • We stated that numerical integration will allow us to calculate velocity and position of an object from its acceleration, hence enabling us to animate the objects motion.

Please feel free to comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.