- Home /
Question by
paid2306 · Mar 05, 2021 at 02:58 PM ·
wheelcollider
Wheel Collider Gearbox
Hi, I'm having problems trying to simulate the gearbox, the main problem I have is that I don't know how to get higher speeds with high gears, this is my script and the values I use. public double kmh_speed;
//COM
[SerializeField] private Vector3 COM;
//RPM
public int rpm;
[SerializeField] private int MIN_RPM;
[SerializeField] private int MAX_RPM;
//GEARS
[SerializeField] private float[] gears;
[SerializeField] private int i_gear;
[SerializeField] private float transmission;
//MOTOR
[SerializeField] private AnimationCurve motor_force;
//WHEELS
[SerializeField] private WheelCollider[] steer_wheels;
[SerializeField] private WheelCollider[] motor_wheels;
//INPUT
public float v_axis;
public float h_axis;
//OTHER
public Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
rb.centerOfMass = COM;
}
private void Update()
{
v_axis = Input.GetAxis("Vertical");
h_axis = Input.GetAxis("Horizontal");
manage_rpm();
//manage_gears();
manage_steer();
kmh_speed = rb.velocity.magnitude*3.6;
if (v_axis!=0) apply_force();
}
private void manage_rpm(){
int new_rpm=0;
int contador=0;
int i;
for(i=0;i<motor_wheels.Length;i++){
if(motor_wheels[i].isGrounded){
new_rpm+=(int)motor_wheels[i].rpm;
contador++;
}
}
if (contador>0) rpm = (int)((new_rpm/(contador)) / transmission / gears[i_gear])+1000;
rpm = Mathf.Clamp(rpm,MIN_RPM,MAX_RPM);
Debug.Log(rpm);
}
private void manage_gears(){
if(rpm>=2500){
rpm = MIN_RPM;
i_gear++;
}
}
private void manage_steer(){
int i;
for(i=0;i<steer_wheels.Length;i++){
steer_wheels[i].steerAngle = 25 * h_axis;
}
}
private void apply_force(){
int i;
for(i=0;i<motor_wheels.Length;i++){
motor_wheels[i].motorTorque = (motor_force.Evaluate(rpm) * transmission * gears[i_gear]) * v_axis;
}
}
private void OnDrawGizmos() {
Gizmos.color = Color.red;
Gizmos.DrawSphere(transform.TransformPoint(COM),0.3f);
}
Gear size 7: 3.19 3 2.5 1.5 1 0.7 0.5
Comment
Unite Europe 2016 - Gearboxes and Gas Pedals - Vehicle Physics in Unity
Your answer
Follow this Question
Related Questions
Wheel falling through ground 3 Answers
Wheels WaterSplash Effect 0 Answers
Why won't my car steer? 1 Answer
how do i change the wheel collider stiffness with a script? 1 Answer
Why the wheel collider in the car example in unity 5 is so big? 0 Answers