- Home /
Question by
$$anonymous$$ · Nov 16, 2019 at 03:17 AM ·
carcar gamecar physicsrealistic
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;
}
}
}
Comment
Answer by jbjbbuhl123 · Feb 21, 2020 at 07:53 AM
maybe you could do something with if(clutchpressed) drivenormally(); else() rollfree();
maybe change friction on the "rollfree"
Your answer
Follow this Question
Related Questions
Better RPM?? 0 Answers
How to make traction control for car? 1 Answer
Shift gear with own RPM? Help please! 0 Answers
Car Gearbox script 1 Answer
Extremely simple car movement 1 Answer