- Home /
Unity 5 Car WheelCollider Acceleration Issue
Recently I needed to make a small car game for a school project. However, after I setup the car and my simple car control script, the car drives fine, but keeps on accelerating after I release the up arrow key and keeps on slowing down after I release the down arrow key. How do I make it so that the car only accelerates only when the key is pressed down? I have tried to change the gravity and sensitivity in the InputManager, but it doesn't work. #pragma strict
var wheelFL : WheelCollider;
var wheelFR : WheelCollider;
var wheelRL : WheelCollider;
var wheelRR : WheelCollider;
var steeringAngle : float;
var throttle : float;
var maxTorque : float;
var speed : float;
function Start () {
}
function Update () {
throttle = Input.GetAxis("Vertical") * maxTorque;
wheelRL.motorTorque = throttle;
wheelRR.motorTorque = throttle;
steeringAngle = Input.GetAxis("Horizontal") * 15;
wheelFL.steerAngle = steeringAngle;
wheelFR.steerAngle = steeringAngle;
speed = Mathf.Round(GetComponent.<Rigidbody>().velocity.magnitude * 3.6);
}
Answer by Cataclysm18 · Jul 10, 2017 at 08:59 PM
To stop the car you should use brakeTorque instead of negative motorTorque. I'm not sure why your care keeps on accelerating, probably because you don't stop the car. try printing the throttle to the screen and check that it's a 0 when you release all keys.
Check this link for simple car control: http://carpe.com.au/slawia/2009/08/unity-wheel-collider-part-3/
Your answer
Follow this Question
Related Questions
Car speed physics problem, accelerates and turns out of controll 0 Answers
WheelCollider rotates mesh wrong 1 Answer
Wheels starts to go when rotate a car 0 Answers
How to detect my car is drifting or not ? 1 Answer
car Wheelies uncontrollably 3 Answers