Applying simple car physics
In this example, we're going to tackle what I consider to be pretty close to the bare minimum of car physics: allowing the player to move forwards, backwards, left and right. No simulation of note will be included beyond the tracking of speed and location.
This sort of physics is usually well-suited for the simple, arcade type driving where you want the player to be able to focus on aspects other than the act of driving itself, such as dodging or shooting.
Getting ready
This recipe relies upon the Geometric Buffer classes discussed in Chapter 3, Procedural Modeling, to build the car mesh. Any representation, be it a 3D mesh or even a 2D image, can be substituted without issue though.
How to do it...
To create your own drivable car:
1. Create a new
Car()
class to hold the display and control logic for a car:class Car {
2. Add instance-level variables to hold the meshes and relative positions of the wheels:
GeometricBuffer<VertexPositionNormalTexture> carBuffer...