Quantcast
Viewing all articles
Browse latest Browse all 146

transmission clutch help!

Good evening everyone, I am designing a car script, and I need to design the clutch, that is, when the car makes the transmission changes, stop accelerating to "step on the clutch" and then accelerate again with the transmission in, style Need For Speed Most Wanted, but I don't know how to design it! here the script, thanks! using UnityEngine; using System.Collections; public class CarScript : MonoBehaviour { public WheelCollider FrontLeftWheel; public WheelCollider FrontRightWheel; public float[] GearRatio; public int CurrentGear = 0; public float EngineTorque = 600.0f; public float MaxEngineRPM = 3000.0f; public float MinEngineRPM = 1000.0f; public float EngineRPM = 0.0f; void Start (){ } void Update (){ //rigidbody.centerOfMass = new Vector3 (rigidbody.centerOfMass.x, -1.5f, rigidbody.centerOfMass.z); rigidbody.centerOfMass = new Vector3 (0, -0.8f, 0); rigidbody.drag = rigidbody.velocity.magnitude / 250; EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm)/2 * GearRatio[CurrentGear]; ShiftGears(); audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 0.1f ; if ( audio.pitch > 2.0f ) { audio.pitch = 2.0f; } 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"); } void ShiftGears (){ int AppropriateGear = CurrentGear; if ( EngineRPM >= MaxEngineRPM ) { for ( int i= 0; i < GearRatio.Length; i ++ ) { if ( FrontLeftWheel.rpm * GearRatio[i] <= MaxEngineRPM ) { AppropriateGear = i; break; } } CurrentGear = AppropriateGear; } if ( EngineRPM <= MinEngineRPM ) { AppropriateGear = CurrentGear; for ( int j= GearRatio.Length-1; j >= 0; j -- ) { if ( FrontLeftWheel.rpm * GearRatio[j] > MinEngineRPM ) { AppropriateGear = j; break; } } CurrentGear = AppropriateGear; } } }

Viewing all articles
Browse latest Browse all 146

Trending Articles