Hovercar rigidbody acceleration


I currently have a hovercar working with physics and the script I created is based off of the hovercar tutorial made by Unity themselves. The problem I am having is that the I am finding the acceleration of the hovercar too high and its reaching its top speed quickly. Is there any way I can implement slower acceleration but maintaining control over the vehicle with the current setup I have below?

N.B. I also want this because I want the hovercars to have different attributes like top speed, acceleration, handling, etc.


Tutorial: Unity Connect (script can be found under video)

The scripts and rigidbody settings are exactly the same except for some few things:


  • Use Gravity is off (I’ll explain later)
  • Interpolate is set to Interpolate (since for some reason my hover car stutters without this)


Check the code comments for the changes (fixed update part only is shown since physics are only done there)

void FixedUpdate()
            // I added my own fake gravity here
            Vector3 appliedGravityForce = -transform.up * 9.81f;
            carRigidbody.AddForce(appliedGravityForce, ForceMode.Acceleration);
            Ray ray = new Ray(carFlyer.position, -transform.up); // used a child object in front of the car as the position to make the detection more accurate
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, hoverHeight * 1.5f)) // made detection be a bit broader
                float proportionalHeight = (hoverHeight - hit.distance) / hoverHeight;
                Vector3 appliedHoverForce = transform.up * proportionalHeight * hoverForce;
                carRigidbody.AddForce(appliedHoverForce, ForceMode.Acceleration);
                Quaternion targetRotation = Quaternion.FromToRotation(transform.up, hit.normal) * carRigidbody.rotation;
                carRigidbody.rotation = Quaternion.Slerp(carRigidbody.rotation, targetRotation, Time.fixedDeltaTime * 3);
                // I adjusted the car's angles to the normal of the ground under it

                Debug.DrawRay(ray.origin, -transform.up, Color.cyan); // just some debug stuff
            carRigidbody.AddRelativeForce(0f, 0f, powerInput * speed);
            carRigidbody.AddRelativeTorque(0f, turnInput * turnSpeed, 0f);

Answering myself for the second time on this forum. Quite disappointed with the community really. But anyways, I managed to find a solution quite a while ago to this problem and I just forgot to mention it, so I’ll explain it here for future reference and for people who are having the same problem:

The high acceleration and low top speed were coming from the high drag value done in the tutorial. This is because drag means how much air resistance the object has… meaning the higher this value, the more force is being applied opposite to the velocity of the object. This keeps the hovercar from losing its “grip” and being able to turn and move in the new direction. Therefore, this means that there is pretty much no direct solution to this problem. I did find a workaround though.

The workaround included me creating a small intermediate variable where when the user presses “W” to go forward, this variable’s value will increase at a certain rate which is being used as a multiplier (between 0 and 1) for a pre-defined variable that is the applied forward force to the car. This makes it so you can control how much acceleration the car can have with any top speed you want. I’ll include a snippet below… hope this helps!

if (Input.GetAxisRaw("Vertical") > 0)
    powerInput = Mathf.Clamp01(powerInput + forwardAcceleration * Time.deltaTime);
    powerInput = Mathf.Clamp01(powerInput - neutralDeceleration * Time.deltaTime);

Variable Key:

powerInput: Value being used to apply as force. Used as a multiplier for the actual force in this case.

forwardAcceleration: pre-defined forward value (the forward acceleration rate)

neutralDeceleration: pre-defined “no-input” value (the deceleration rate for when the user isn’t pressing anything)