Graphics Reference
In-Depth Information
Wheel_RL
Wheel_RR
WheelMeshes
Wheel_FL
Wheel_FR
Wheel_RL
Wheel_RR
The script derives from MonoBehavior so that it can tap into the engine's Update()
function:
using UnityEngine;
using System.Collections;
public class BaseWheelAlignment : MonoBehavior
{
Skipping by the variable declarations, we move down to the Start() function.
myTransform is a cached reference to the wheel transform, a default rotation value is
stored in zeroRotation, and there's also a cached reference to the transform, which has the
WheelCollider attached to it, to be stored in the variable colliderTransform:
void Start ()
{
// cache some commonly used things...
myTransform= transform;
zeroRotation= Quaternion.identity;
colliderTransform= CorrespondingCollider.transform;
}
This Update() function works by casting a ray down from the center of the
WheelCollider with the intention of placing the wheel mesh up from the point of impact.
If nothing is picked up by the raycast, the wheel mesh is simply positioned at a point down
from the center of the WheelCollider instead:
void Update ()
{
// define a hit point for the raycast collision
RaycastHit hit;
The WheelCollider.center property returns a value from the WheelCollider's local
coordinate space, so Transform.TransformPoint is used to convert it into a world space
coordinate that we can use to start the ray cast from:
Vector3 ColliderCenterPoint=
colliderTransform.TransformPoint( CorrespondingCollider.
center );
Search WWH ::




Custom Search