I have a simple car in my game using these two scritps:
var FrontLeftWheel : WheelCollider;
var FrontRightWheel : WheelCollider;
var GearRatio : float[];
var CurrentGear : int = 0;
var EngineTorque : float = 230.0;
var MaxEngineRPM : float = 3000.0;
var MinEngineRPM : float = 1000.0;
private var EngineRPM : float = 0.0;
function Start () {
rigidbody.centerOfMass += Vector3(0, -.75, .5);
}
function Update () {
EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm)/2 * GearRatio[CurrentGear];
ShiftGears();
audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 1.0 ;
if ( audio.pitch > 2.0 ) {
audio.pitch = 2.0;
}
FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis("Vertical");
FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis("Vertical");
FrontLeftWheel.steerAngle = 10 * Input.GetAxis("Horizontal");
FrontRightWheel.steerAngle = 10 * Input.GetAxis("Horizontal");
}
function ShiftGears() {
if ( EngineRPM >= MaxEngineRPM ) {
var AppropriateGear : int = CurrentGear;
for ( var i = 0; i < GearRatio.length; i ++ ) {
if ( FrontLeftWheel.rpm * GearRatio *< MaxEngineRPM ) {*
AppropriateGear = i;
break;
}
}
CurrentGear = AppropriateGear;
}
if ( EngineRPM <= MinEngineRPM ) {
AppropriateGear = CurrentGear;
for ( var j = GearRatio.length-1; j >= 0; j – ) {
if ( FrontLeftWheel.rpm * GearRatio[j] > MinEngineRPM ) {
AppropriateGear = j;
break;
}
}
CurrentGear = AppropriateGear;
}
}
and this one:
var CorrespondingCollider : WheelCollider;
var SlipPrefab : GameObject;
public var RotationValue : float = 0.0;
function Update () {
var hit : RaycastHit;
var ColliderCenterPoint : Vector3 = CorrespondingCollider.transform.TransformPoint( CorrespondingCollider.center );
if ( Physics.Raycast( ColliderCenterPoint, -CorrespondingCollider.transform.up, hit, CorrespondingCollider.suspensionDistance + CorrespondingCollider.radius ) ) {
transform.position = hit.point + (CorrespondingCollider.transform.up * CorrespondingCollider.radius);
}else{
transform.position = ColliderCenterPoint - (CorrespondingCollider.transform.up * CorrespondingCollider.suspensionDistance);
}
transform.rotation = CorrespondingCollider.transform.rotation * Quaternion.Euler( RotationValue, CorrespondingCollider.steerAngle, 0);
RotationValue += CorrespondingCollider.rpm * ( 360/60 ) * Time.deltaTime;
var CorrespondingGroundHit : WheelHit;
CorrespondingCollider.GetGroundHit( CorrespondingGroundHit );
if ( Mathf.Abs( CorrespondingGroundHit.sidewaysSlip ) > 1.5 ) {
if ( SlipPrefab ) {
Instantiate( SlipPrefab, CorrespondingGroundHit.point, Quaternion.identity );
}
}
}
with this tutorial:
Creating a driveable vehicle in Unity 3D - YouTube
It works fine but now I want a speedometer that goes up as I go faster. how can I do this