Graphics Reference
In-Depth Information
myTransform.rotation= colliderTransform.rotation *
Quaternion.Euler( RotationValue,
CorrespondingCollider.steerAngle, 0 );
// increase the rotation value by the rotation speed (in
// degrees per second)
RotationValue+= CorrespondingCollider.rpm * ( 360 / 60 ) *
Time.deltaTime;
// define a wheelhit object, this stores all of the data
// from the wheel collider and will allow us to determine
// the slip of the tire.
WheelHit correspondingGroundHit= new WheelHit();
CorrespondingCollider.GetGroundHit( out
correspondingGroundHit );
// if the slip of the tire is greater than 2.0f, and the
// slip prefab exists, create an instance of it on the ground at
// a zero rotation.
if ( Mathf.Abs( correspondingGroundHit.sidewaysSlip ) >
slipAmountForTireSmoke ) {
if ( slipPrefab ) {
SpawnController.Instance.Spawn( slipPrefab,
correspondingGroundHit.point, zeroRotation );
}
}
}
}
5.3.3 Script Breakdown
The BaseWheelAlignment.cs script may be used to align the wheel meshes to the wheel
colliders, as well as to provide a little extra functionality in spawning tire smoke as the
wheel is slipping. The smoke is optional, of course, but it's here in case you need it.
Each wheel should have a BaseWheelAlignment script attached to it (i.e., the wheel
mesh not the WheelCollider) and then a reference to the WheelCollider component
provided to this script via the Unity editor Inspector window, into the variable named
CorrespondingCollider. The wheels should be independent of the WheelColliders for them
to move correctly; do not parent the wheel meshes to the colliders.
In the example game Metal Vehicle Doom , the vehicle looks like this in the hierarchy
window:
Car
Body
Colliders (body)
WheelColliders
Wheel_FL
Wheel_FR
Search WWH ::




Custom Search