GAME PROGRAMMING RESOURCES

SIMPLE CAR WITH
WORKING SUSPENSIONS
AND REALISTIC DYNAMICS

In this tutorial we assume you fully understand this document.

Open, compile and test the SimpleCar project by following the procedure described in the Quick Start Tutorial for the BallGame project.

On your screen, there should be a strange car. You can drive around by pressing the arrow keys. Press [Esc] to terminate.

The source code is fully commented and examining it is strongly recommended!

It includes 3 function calls per wheel to configure wheel physics and suspensions and 3 function calls per wheel to implement steering and throttle. Car physics is automatically managed by the system.

Don't forget to refer to Reference document for details on all functions called in the source code!

REPLACE THE DEMO CAR
WITH YOUR OWN CAR MODEL

1. Make a mesh for the car body and a mesh for the wheel. Make sure that car and wheel proportions are proper. Save both as .x (DirectX®) files.



Note that you need to make one single wheel mesh, because we are using the same identical model for all wheels.

2. By using the car body mesh as a reference, make a collision detection model and save it as an '_.x' file.



3. By using the car body mesh as a reference, make also a mass model, and save it as an '__.x' file. Then generate the .spg file from the collision and the mass models.



Note that, in order to improve the car stability, we have placed the volume so that the resulting center of mass will lie well below its supposed location.

As you know, there is no need for the mass model to match the visible mesh geometry, and there is no need to try to closely simulate real world mass distribution either.

Actually, the mass model is the best tool you have to influence the physics behavior of your dynamic bodies. 3Impact game engine allows you to closely simulate real-world dynamics, but you'll find that in a game you have to focus on playability and basically forget about accurate simulation. Keep in mind that, usually, games are supposed to be more funny than realistic.

Limiting real-life dynamics is common practice when programming a physics engine. Sometimes, you may even want to apply specific forces and constraints to prevent some behaviors.

4. By using the wheel mesh as a reference, make finally a collision detection model and a mass model for the wheel.



Note that wheels should always be approximated to spheres, for collision detection purposes, in order to ensure a clean rolling.

REMARKS

  • The DLL code (see source) calls iBodySGCreate() four times, in order to create the four wheels for the car from the same .spg resource. Similarly it calls four times iMeshBodyCreate() for the same .x resource and iMeshBodyShadowCasterCreate() for the same _shadow.x resource.


  • The four wheel bodies are attached to the car-body body by calling iWheelCreate() for each of them. Note that you can adjust wheel locations by changing the position vector passed to the function.


  • Examine and customize the source code to understand how it works.