Graphics Reference
In-Depth Information
{
// Define the variables used in the script, the Corresponding
// collider is the wheel collider at the position of
// the visible wheel, the slip prefab is the prefab instantiated
// when the wheels slide, the rotation value is the
// value used to rotate the wheel around its axle.
public WheelCollider CorrespondingCollider;
public GameObject slipPrefab;
public float slipAmountForTireSmoke= 50f;
private float RotationValue = 0.0f;
private Transform myTransform;
private Quaternion zeroRotation;
private Transform colliderTransform;
private float suspensionDistance;
void Start ()
{
// cache some commonly used things...
myTransform= transform;
zeroRotation= Quaternion.identity;
colliderTransform= CorrespondingCollider.transform;
}
void Update ()
{
// define a hit point for the raycast collision
RaycastHit hit;
// Find the collider's center point, you need to do this
// because the center of the collider might not actually be
// the real position if the transform's off.
Vector3 ColliderCenterPoint=
colliderTransform.TransformPoint( CorrespondingCollider.
center );
// now cast a ray out from the wheel collider's center the
// distance of the suspension, if it hit something, then use
// the "hit" variable's data to find where the
// wheel hit, if it didn't, then set the wheel
// to be fully extended along the suspension.
if ( Physics.Raycast( ColliderCenterPoint,
-colliderTransform.up, out hit,
CorrespondingCollider.suspensionDistance +
CorrespondingCollider.radius ) ) {
myTransform.position= hit.point +
(colliderTransform.up *
CorrespondingCollider.radius);
} else {
myTransform.position= ColliderCenterPoint -
( colliderTransform.up *
CorrespondingCollider.suspensionDistance );
}
// now set the wheel rotation to the rotation of the
// collider combined with a new rotation value. This new value
// is the rotation around the axle, and the rotation from
// steering input.
Search WWH ::




Custom Search