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);
}