Panda3D Manual: Bullet VehiclesBullet comes with a simple vehicle controller, which can be used for arcade style vehicle simulations. Instead of simulation of each wheel and chassis as separate rigid bodies connected by joints, it simply uses a single rigid body for the chassis. Collision detection for the wheels is approximated by ray casts, and the tire friction is a basic anisotropic friction model. This approach to vehicle modelling is called "raycast vehicle", and it is used widely in commercial and non-commercial driving games.
SetupIn order to create a vehicle we first have to create an ordinary dynamic rigid body. This rigid body will serve as the vehicle chassis. Then we can create a new instance of The following code snippet shows how this could be done. TODO
WheelsOne we have created the chassis and the vehicle we can add wheels to the vehicle. We can create a new wheel using the The following sample shows how to create and configure a wheel. In this case a front wheel is created. Front wheels are steerable. TODO
Steering and Engine/BrakeFinally we need to control steering and engine/brakes. This is best done using a task, and keeping the current steering angle around somewhere in a variable. Here we use a very simple model of controlling the steering angle. If 'turnLeft' or 'turnRight' keys are pressed the sterring angle will increase/decrease at a constant rate, until a maximum steering angle is achieved. No relaxation is applied. Therefor we also define constants for the maximum steering angle (here: steeringClamp) and the rate at which the steering angle increases/decreases (here: steeringIncrement). The engine force and brake model shown is very simple too. If 'forward' is pressed then the engine force will be the maximum engine force, otherwise engine force will be zero. Likewise for the brakes. Once the steering angle and engine/brake forces are determined they will be applied to the wheels. Each wheel - addressed by it's index, i. e. 0 to 3 for a four-wheel car - can be individually assigned values for steering and engine/brake force. This way front/rear drives or four-wheel-drives can be simulated. The following code snippet shows pseudocode for controlling steering and engine/brakes. TODO More realistic control models can be invented, in order to meet the control requirements of individual driving games. For example:
However, it is up to you do invent such controls. What Bullet requires is that you provide the steering angle and the engine and brake force. © Carnegie Mellon University 2010 |