Vehicle


We need to revisit the runabout model to prepare it for use as a mountable vehicle. The enhancement is not complex.

Model

Open the runabout model using MilkShape and add some mount nodes, as shown in Figure 22.2. These are joints, added using the Joint tool on the Model tab and named on the Joints tab.

click to expand
Figure 22.2: Car mount nodes.

Name the one in the driver's position mount0 and the other mount1. Re-export your car and save it to C:\koob\control\data\models\vehicles\runabout.dts.

Earlier, when you mounted the vehicle using the filler model, the model was mounted to the local origin (0,0,0) of the car. Now the model will be mounted where you've specified with the nodes.

Datablock

We need to add a few things to the datablock. Open your file C:\koob\control\server\vehicles\car.cs and find the datablock. It looks like this:

 datablock WheeledVehicleData(DefaultCar) 

Add the following to the end of the datablock:

 mountPose[0]       = "sitting"; mountPose[1]       = "sitting"; numMountPoints     = 2; 

The properties are pretty straightforward—"sitting" refers to the name of the sequence in the model that we created earlier with the Hero model in the sitting pose. The name was defined in a special material.

Table 22.1 contains descriptions of the most significant properties available for adjustment in the WheeledVehicleData datablock.

Table 22.1: WheeledVehicleData Properties

Command

Description

MaxDamage

Specifies the maximum number of damage points a vehicle can take before it becomes disabled. Destroyed and disabled states are calculated percentages of this value.

DestroyedLevel

Specifies the percentage of MaxDamage that, when reached, causes the vehicle's onDestroyed callback to be called by the engine.

DisabledLevel

Specifies the percentage of MaxDamage that, when reached, causes the vehicle's onDestroyed callback to be called by the engine.

MaxSteeringAngle

Maximum steering angle.

TireEmitter

Same dust emitter as used by all the tires.

CameraRoll

Rolls the camera with the vehicle when it rolls.

CameraMaxDist

Farthest distance from the vehicle in third-person view.

CameraOffset

Vertical offset from the camera mount point.

CameraLag

Velocity lag of the camera in third-person view.

CameraDecay

Decay per second rate of velocity lag in third-person view.

Mass

Mass of the vehicle in quasi-kilograms.

MassCenter

Center of mass for rigid body expressed in object space 3D coordinates.

MassBox

Size of box used for moment of inertia; if 0 it defaults to the object's bounding box.

Drag

Drag coefficient. Used to counteract acceleration.

BodyFriction

Determines "stickiness" when the body brushes against the terrain or other objects.

BodyRestitution

Determines, by using rigid body physics, how much deformation is reversed.

MinImpactSpeed

Specifies the speed at and above which the vehicle's onImpact callback will be called by the engine.

SoftImpactSpeed

Specifies the speed at and above which the engine will play the vehicle's SoftImpact sound.

HardImpactSpeed

Specifies the speed at and above which the engine will play the vehicle's HardImpact sound.

Integration

Physics integration: TickSec/Rate. Higher values here yield higher integration. Higher integration leads to more accurate simulation but at the potential cost of CPU performance.

CollisionTol

Collision distance tolerance. A higher number means that a collision will be detected sooner (objects are farther apart) than with a lower number.

ContactTol

Contact velocity tolerance. How much leeway is allowed in determining whether objects have collided or have merely contacted, or brushed, each other. A higher number means that a more forceful contact can occur without the contact being considered a collision.

EngineTorque

Engine power, which causes acceleration, which leads to higher velocities.

EngineBrake

Braking when throttle is 0—simulates the internal "drag" of an engine that tends to slow a vehicle when it is in gear.

BrakeTorque

When brakes are applied, works as the opposite of EngineTorque.

MaxWheelSpeed

The maximum rotation speed of the wheels, which directly affects the speed of the vehicle based on the wheel diameter and deformation factors. Wheel speed derives from engine speed and other factors.

MaxEnergy

The maximum amount of energy available to the vehicle for conversion into motion. Energy can be seen to be the same as fuel load.

JetForce

Additional boost force—a holdover term from the Tribes days. Means the same as acceleration.

MinJetEnergy

The smallest amount of energy needed to apply a jetting boost.

JetEnergyDrain

How quickly the energy of the vehicle is drained by use of jetting.

JetSound

The sound played when jetting or accelerating.

EngineSound

The sound played when the engine is idling.

SquealSound

The sound played when the tires skid.

SoftImpactSound

The sound played when a mild collision occurs.

HardImpactSound

The sound played when a serious collision occurs.

WheelImpactSound

The sound played when the wheels and tires hit something.

Two other datablocks have significant effect on the behavior of the car: WheeledVehicleTire and WheeledVehicleSpring, shown here:

 datablock WheeledVehicleTire(DefaultCarTire) {    shapeFile = "~/data/models/vehicles/wheel.dts";    staticFriction = 4;    kineticFriction = 1.25;    lateralForce = 18000;    lateralDamping = 4000;    lateralRelaxation = 1;    longitudinalForce = 18000;    longitudinalDamping = 4000;    longitudinalRelaxation = 1; }; datablock WheeledVehicleSpring(DefaultCarSpring) {    // Wheel suspension properties    length = 0.85;              // Suspension travel    force = 3000;               // Spring force    damping = 600;              // Spring damping    antiSwayForce = 3;          // Lateral anti-sway force }; 

In the WheeledVehicleTire datablock you can see that tires act as springs in two ways: They generate lateral and longitudinal forces to move the vehicle. These distortion/spring forces are what convert wheel angular velocity into forces that act on the rigid body.




3D Game Programming All in One
3D Game Programming All in One (Course Technology PTR Game Development Series)
ISBN: 159200136X
EAN: 2147483647
Year: 2006
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net