Graphics Reference
In-Depth Information
car would float just above its resting place against the ground until the race started when
it would drop down some as gravity is applied:
public void CheckLock()
{
if (isLocked)
{
// control is locked out and we should be stopped
steer = 0;
brake = 0;
motor = 0;
// hold our rigidbody in place (but allow the Y to
// move so the car may drop to the ground if it is not
// exactly matched to the terrain)
Vector3 tempVEC = myBody.velocity;
tempVEC.x = 0;
tempVEC.z = 0;
myBody.velocity = tempVEC;
}
}
steer, motor, and brake are float variables used for moving the vehicle around.
GetInput() uses Mathf.Clamp to keep them to reasonable values as they are set by the
default input system:
public virtual void GetInput()
{
// calculate steering amount
steer= Mathf.Clamp( default_input.GetHorizontal() , -1, 1 );
// how much accelerator?
motor= Mathf.Clamp( default_input.GetVertical() , 0, 1 );
// how much brake?
brake= -1 * Mathf.Clamp( default_input.GetVertical() , -1, 0 );
}
}
5.3.2 Wheel Alignment
WheelColliders will do a great job of acting like wheels, but if we want to actually see
wheels, there is still more work to be done; each wheel mesh needs to be positioned to
match that of its WheelCollider counterpart.
The script in full looks like this:
// based on work done in this forum post:
// http://forum.unity3d.com/threads/50643-How-to-make-a-physically-real-
// stable-car-with-WheelColliders
// by Edy.
using UnityEngine;
using System.Collections;
public class BaseWheelAlignment : MonoBehavior
Search WWH ::




Custom Search