Monday 13 August 2007

Game Physics & Collision Detection


There are many racing game physics that can be implemented such as gravity, friction, engine physics, car dynamics and springs physics. These physics are important to achieve realism in game play. For this project, the basic law of motion and collision detection will be implemented as shown in Figure 39. These include:

  1. Car moves towards as the accelerate key is pushed or moves backwards if the reverse key is pushed.
  2. Some elements may pull the car back or slow it down such as friction or braking.
  3. Gravity pulls the car down and keeps the car on the road.

Objects that are moving through the world need to be checked against the geometry and all other objects in the world to see that it does not pass through or get too close to any of them. For instance, I would check if any of the four wheels collide with the guard rail by checking the four wheel positions (or at least the most outer parts of the car) still allow you to do the basic collision detection. If the car is crashing into the right guard rail, it means collision happens at the front right side of the car and vice-versa. Collision response is to rotate the car to opposite direction and slow it down due to the crash. Collision between cars also must be calculated to reduce the car’s defence status bar so that the game will over when the car’s defence equal or less than zero. The following Source code shows the pseudo code for checking the collision with the guard rails.

Check all 4 corner points of the car.

For all 4 corners {

Determine the distance between the corner to the rail.

If it less than or equal 0 then

{

Collision happens.

Bring out the collision event

{

I. 2nd law of motion, force the car back on the road and reduce speed.

II. Determine the collision impulse and show collision effects.

III. Play collision sound

IV. Shake camera.

}

}

}

No comments: