- Home /
WheelCollider: Slowing down wheels in air
Hello all,
I'm making a 2.5D car game (Unity 5.3.4f1) with a lot of jumping in it. I'm almost done with the controls and behaviour of the car, but there's one thing I can not figure out.
The car have 4 wheelcolliders and are working great when grounded. When releasing the throttle the car and wheels are slowing down. So the audio pitching is working great. But when the car goes at maxpeed of the ground and into the air, the cars rpm is stuck at full throttle/maxspeed and not slowing down until the car is hitting the ground again. Audio pitching is at max rpm (does have Mathf.Clamp). When the car is leaving the ground while not at maxspeed, the wheels are slowing down as wanted.
When releasing the throttle (grounded and in the air) the motorTorque = 0;
Does someone know what can be the problem? Also checked the setting for the wheelcolliders but nothing works.
The code for throttle behaviour:
void maximumSpeed () {
//Control of max speed
if (Input.GetKey (KeyCode.RightArrow) && currentSpeed <= maxSpeed && currentSpeed >= noSpeed) {
wheelRR.motorTorque = maxTorque * Input.GetAxis ("Horizontal");
wheelRL.motorTorque = maxTorque * Input.GetAxis ("Horizontal");
}
else if (Input.GetKey (KeyCode.LeftArrow) && currentSpeed >= -maxReverseSpeed && currentSpeed <= noSpeed) {
wheelRR.motorTorque = maxTorque * Input.GetAxis ("Horizontal");
wheelRL.motorTorque = maxTorque * Input.GetAxis ("Horizontal");
}
else {
wheelRR.motorTorque = 0f;
wheelRL.motorTorque = 0f;
}
}
I tried deleting all unnecessary code accept this and the currentspeed code and that didn't work. So it has to be something with these lines of code.
Here the currentspeed code:
void calculateSpeed () {
//Calculates the speed of the car
currentSpeed = 2*22/7*wheelRR.radius*wheelRR.rpm*60/1000;
currentSpeed = $$anonymous$$athf.Clamp ((currentSpeed), currentSpeed, maxSpeed);
currentSpeed = $$anonymous$$athf.Round(currentSpeed);
}
Does anyone know what the problem can be? Thanks
Answer by Thats_Life · Jul 20, 2016 at 02:21 PM
Fixed it with:
if (Mathf.Abs (currentSpeed) > maxSpeed) {
wheelFR.motorTorque = 0f;
wheelFL.motorTorque = 0f;
wheelRR.motorTorque = 0f;
wheelRL.motorTorque = 0f;
}
In Update ()
Your answer
Follow this Question
Related Questions
Average Settings for a car and its controller in unity. 0 Answers
How to properly use WheelCollider GetWorldPos 0 Answers
WheelCollider Problem 1 Answer
How to make a car move forward indefinitly ? 2 Answers
How can I get current lateral and longitudial friction forces from standart WheelColliders? 0 Answers