Car Acceleration is mindblowingly slow.

I just need it to get up to speed faster. I tried:

  1. Weight
  2. Wheel mass
  3. re Size model
  4. did stiffen suspension with Wheel Colliders
  5. modify the drag

This all doesn’t work for me. the car is up to max speed in about 2 minutes when it should be 30 seconds in real life.
PHOTOS:
The car itself:


This is one wheel collider (All same settings):

This is my code:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CarController : MonoBehaviour
{
    private float horizontalInput;
    private float verticalInput;
    private float steerAngle;
    private bool isBreaking;

    public WheelCollider frontLeftWheelCollider;
    public WheelCollider frontRightWheelCollider;
    public WheelCollider rearLeftWheelCollider;
    public WheelCollider rearRightWheelCollider;
    public Transform frontLeftWheelTransform;
    public Transform frontRightWheelTransform;
    public Transform rearLeftWheelTransform;
    public Transform rearRightWheelTransform;

    public float maxSteeringAngle = 30f;
    public float motorForce = 50f;
    public float brakeForce = 0f;


    private void FixedUpdate()
    {
        GetInput();
        HandleMotor();
        HandleSteering();
        UpdateWheels();
    }

    private void GetInput()
    {
        horizontalInput = Input.GetAxis("Horizontal");
        verticalInput = Input.GetAxis("Vertical");
        isBreaking = Input.GetKey(KeyCode.Space);
    }

    private void HandleSteering()
    {
        steerAngle = maxSteeringAngle * horizontalInput;
        frontLeftWheelCollider.steerAngle = steerAngle;
        frontRightWheelCollider.steerAngle = steerAngle;
    }

    private void HandleMotor()
    {
        frontLeftWheelCollider.motorTorque = verticalInput * motorForce;
        frontRightWheelCollider.motorTorque = verticalInput * motorForce;

        brakeForce = isBreaking ? 3000f : 0f;
        frontLeftWheelCollider.brakeTorque = brakeForce;
        frontRightWheelCollider.brakeTorque = brakeForce;
        rearLeftWheelCollider.brakeTorque = brakeForce;
        rearRightWheelCollider.brakeTorque = brakeForce;
    }

    private void UpdateWheels()
    {
        UpdateWheelPos(frontLeftWheelCollider, frontLeftWheelTransform);
        UpdateWheelPos(frontRightWheelCollider, frontRightWheelTransform);
        UpdateWheelPos(rearLeftWheelCollider, rearLeftWheelTransform);
        UpdateWheelPos(rearRightWheelCollider, rearRightWheelTransform);
    }

    private void UpdateWheelPos(WheelCollider wheelCollider, Transform trans)
    {
        Vector3 pos;
        Quaternion rot;
        wheelCollider.GetWorldPose(out pos, out rot);
        trans.rotation = rot;
        trans.position = pos;
    }

}

How can I make it accelerate faster?

(Edit: if I need to modify my script please say which line with what I’m normally modeling content not coding I’m new to C3 thank you in advanced!)

Hi!

I don’t know if it can help you, but what I did a long time ago is add more power to the engine to be able to accelerate as fast as possible.

Try this:

frontLeftWheelCollider.motorTorque = verticalInput * 15 * motorForce;
frontRightWheelCollider.motorTorque = verticalInput * 15 * motorForce;
  private void HandleMotor()
    {
        frontLeftWheelCollider.motorTorque = verticalInput * 1000 * motorForce;
        frontRightWheelCollider.motorTorque = verticalInput * 1000 * motorForce;

        brakeForce = isBreaking ? 3000f : 0f;
        frontLeftWheelCollider.brakeTorque = brakeForce;
        frontRightWheelCollider.brakeTorque = brakeForce;
        rearLeftWheelCollider.brakeTorque = brakeForce;
        rearRightWheelCollider.brakeTorque = brakeForce;
    }

this still doesn’t work it still is waaay too slow

May be yo can modify motorForce. Or mass to rigidbody.

If you want, tomorrow shares with you my code. Maybe help you

If you are really trying to simulate wheels spinning to accelerate the car, be aware that you will soon run into all kinds of physics stability limitations as the wheels spin faster and faster.

To this end the default limit to Unity’s angular rotation on a Rigidbody is only about one revolution per second (7 rad / second), no matter how much torque you apply to it. That’s to keep things stable.

You can tweak this limit on your wheels:

I quote from the above documentation:

The maximimum angular velocity of the rigidbody measured in radians per second. (Default 7) range { 0, infinity }.

The angular velocity of rigidbodies is clamped to maxAngularVelocity to avoid numerical instability with fast rotating bodies. Because this may prevent intentional fast rotations on objects such as wheels, you can override this value per rigidbody.

EDIT: The Very Very Valet (for Nintendo Switch) guy made a REALLY cool vehicle physics tutorial here. No wheel colliders, just forces to simulate it all.

3 Likes

I already modified the motor force… mass and other components. that didn’t work though

The thing is I have one rigid body on the car should I make separate ones per wheel colider?

I assumed you had ones on the wheels but looking at the WheelCollider API, it appears it is not necessary.

Therefore I think my comment about max angular velocity DOES NOT apply in this case.

how can my car turn left or right no matter forward or reverse? My tyre can turn left and right but when i turn my car wheel but my car cannot move either forward or reverse. I am doing using joystick(bluetooth controller for VR application). Here is my C# script.

7124255–850799–CarController.cs (3.75 KB)

This has absolutely nothing to do with this topic. Please don’t hijack old topics, it is against forum rules.

Instead, start your own new post. It’s FREE!

When you post, it is critical that you make yourself understood properly.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

How to understand compiler and other errors and even fix them yourself:

https://forum.unity.com/threads/assets-mouselook-cs-29-62-error-cs1003-syntax-error-expected.1039702/#post-6730855

1 Like

Hi, i see you problem right there, i don’t know if you still need a solution for that or if you found one in 2 years, lol. So i had the exactly same problem as you and found out that it’s because of the script, of course this is a common car controller script that many people use, but if you need more control over the acceleration you can use this script instead;

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ACC : MonoBehaviour
{
public WheelCollider[ ] wheels;
public float motorPower = 100;
public float steerPower = 100;
void FixedUpdate()
{
foreach (var wheel in wheels){
wheel.motorTorque = Input.GetAxis(“Vertical”) * motorPower;
}
GetComponent().maxAngularVelocity = 10000;
for (int i = 0; i < wheels.Length; i++)
{
if(i < 2)
{
wheels_.steerAngle = Input.GetAxis(“Horizontal”) * steerPower;_
}
}
}
}
--------------------------------------------------------------------
this script has the main things but also can be better, you can know how to get it better in this video
https://www.youtube.com/watch?v=f_ZO2gv4_z0
by pablos lab.

Thanks i might still use this!