Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Wheel Collider Acceleration WAY TOO SLOW

Discussion in 'Physics' started by PixelCloudInc, Aug 18, 2019.

  1. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    195
    So I'm working on a top - down racing game (not drifting) which includes high speed cars and I'm using a very simple controller... However the acceleration is takes forever... My testing car is the Mclaren P1 GTR which can go from 0-60 mph in 2.4 seconds. But with unity it took over 40 seconds to reach 50 mph ...
    Here is my controller script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CarController : MonoBehaviour
    6. {
    7.     public void GetInput()
    8.     {
    9.         m_horizontalInput = Input.GetAxis("Horizontal");
    10.         m_verticalInput = Input.GetAxis("Vertical");
    11.     }
    12.  
    13.     private void Steer()
    14.     {
    15.         m_steeringAngle = maxSteerAngle * m_horizontalInput;
    16.         frontDriverW.steerAngle = m_steeringAngle;
    17.         frontPassengerW.steerAngle = m_steeringAngle;
    18.     }
    19.  
    20.     private void Accelerate()
    21.     {
    22.         frontDriverW.motorTorque = m_verticalInput * motorForce;
    23.         frontPassengerW.motorTorque = m_verticalInput * motorForce;
    24.     }
    25.  
    26.     private void UpdateWheelPoses()
    27.     {
    28.         UpdateWheelPose(frontDriverW, frontDriverT);
    29.         UpdateWheelPose(frontPassengerW, frontPassengerT);
    30.         UpdateWheelPose(rearDriverW, rearDriverT);
    31.         UpdateWheelPose(rearPassengerW, rearPassengerT);
    32.     }
    33.  
    34.     private void UpdateWheelPose(WheelCollider _collider, Transform _transform)
    35.     {
    36.         Vector3 _pos = _transform.position;
    37.         Quaternion _quat = _transform.rotation;
    38.  
    39.         _collider.GetWorldPose(out _pos, out _quat);
    40.  
    41.         _transform.position = _pos;
    42.         _transform.rotation = _quat;
    43.     }
    44.  
    45.     private void FixedUpdate()
    46.     {
    47.         GetInput();
    48.         Steer();
    49.         Accelerate();
    50.         UpdateWheelPoses();
    51.     }
    52.  
    53.     private float m_horizontalInput;
    54.     private float m_verticalInput;
    55.     private float m_steeringAngle;
    56.  
    57.     public WheelCollider frontDriverW, frontPassengerW;
    58.     public WheelCollider rearDriverW, rearPassengerW;
    59.     public Transform frontDriverT, frontPassengerT;
    60.     public Transform rearDriverT, rearPassengerT;
    61.     public float maxSteerAngle = 30;
    62.     public float motorForce = 50;
    63. }
    And my wheel collider setup...
    https://imgur.com/a/VRAM6fG
    Also I'm new to wheel colliders so like please go easy on me...
     
  2. Marcos-Schultz

    Marcos-Schultz

    Joined:
    Feb 24, 2014
    Posts:
    381
    Nofer likes this.
  3. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    195
  4. wbeltran

    wbeltran

    Joined:
    Feb 8, 2018
    Posts:
    3
    I have a very similar issue, did you get it working?
     
  5. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    195
    Well I did what Marcos-Schultz said... Regarding acceleration yes it was fixed but turning is not good at all.
     
    sickshredzz likes this.
  6. davimi71

    davimi71

    Joined:
    Feb 4, 2019
    Posts:
    1
    Try to lower the center of the mass of the rigidbody of the car. It might be enought 0.1 mt.
     
  7. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    195
    thanks
     
  8. florinel2102

    florinel2102

    Joined:
    May 21, 2019
    Posts:
    75

    Thank you for sharing these values with us :) it helped me to increase power car and also the wheels don't rotate too much .
     
    Marcos-Schultz likes this.
  9. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    Where do I put it in the script?


    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class CarController : MonoBehaviour
    7. {
    8.     private float horizontalInput;
    9.     private float verticalInput;
    10.     private float steerAngle;
    11.     private bool isBreaking;
    12.  
    13.     public WheelCollider frontLeftWheelCollider;
    14.     public WheelCollider frontRightWheelCollider;
    15.     public WheelCollider rearLeftWheelCollider;
    16.     public WheelCollider rearRightWheelCollider;
    17.     public Transform frontLeftWheelTransform;
    18.     public Transform frontRightWheelTransform;
    19.     public Transform rearLeftWheelTransform;
    20.     public Transform rearRightWheelTransform;
    21.  
    22.     public float maxSteeringAngle = 30f;
    23.     public float motorForce = 50f;
    24.     public float brakeForce = 0f;
    25.  
    26.  
    27.     private void FixedUpdate()
    28.     {
    29.         GetInput();
    30.         HandleMotor();
    31.         HandleSteering();
    32.         UpdateWheels();
    33.     }
    34.  
    35.     private void GetInput()
    36.     {
    37.         horizontalInput = Input.GetAxis("Horizontal");
    38.         verticalInput = Input.GetAxis("Vertical");
    39.         isBreaking = Input.GetKey(KeyCode.Space);
    40.     }
    41.  
    42.     private void HandleSteering()
    43.     {
    44.         steerAngle = maxSteeringAngle * horizontalInput;
    45.         frontLeftWheelCollider.steerAngle = steerAngle;
    46.         frontRightWheelCollider.steerAngle = steerAngle;
    47.     }
    48.  
    49.     private void HandleMotor()
    50.     {
    51.         frontLeftWheelCollider.motorTorque = verticalInput * motorForce;
    52.         frontRightWheelCollider.motorTorque = verticalInput * motorForce;
    53.  
    54.         brakeForce = isBreaking ? 3000f : 0f;
    55.         frontLeftWheelCollider.brakeTorque = brakeForce;
    56.         frontRightWheelCollider.brakeTorque = brakeForce;
    57.         rearLeftWheelCollider.brakeTorque = brakeForce;
    58.         rearRightWheelCollider.brakeTorque = brakeForce;
    59.     }
    60.  
    61.     private void UpdateWheels()
    62.     {
    63.         UpdateWheelPos(frontLeftWheelCollider, frontLeftWheelTransform);
    64.         UpdateWheelPos(frontRightWheelCollider, frontRightWheelTransform);
    65.         UpdateWheelPos(rearLeftWheelCollider, rearLeftWheelTransform);
    66.         UpdateWheelPos(rearRightWheelCollider, rearRightWheelTransform);
    67.     }
    68.  
    69.     private void UpdateWheelPos(WheelCollider wheelCollider, Transform trans)
    70.     {
    71.         Vector3 pos;
    72.         Quaternion rot;
    73.         wheelCollider.GetWorldPose(out pos, out rot);
    74.         trans.rotation = rot;
    75.         trans.position = pos;
    76.     }
    77.  
    78. }
     
  10. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    195
    in you wheel collider settings
     
    florinel2102 likes this.
  11. simonhailemariam2

    simonhailemariam2

    Joined:
    Feb 17, 2021
    Posts:
    1
    mine is moving slow even i changed every setting pls help
     
  12. dcmrobin

    dcmrobin

    Joined:
    Feb 15, 2021
    Posts:
    7
    I doubt this is normal: my car can go up to and beyond Mach 1... but it also takes ages to get there. Would changing the physics material of the ground to have more friction help?
     
  13. KoddakJrell

    KoddakJrell

    Joined:
    Jan 17, 2019
    Posts:
    1
    Not according to how I interpret the manual for Wheel Colliders. it states the following under Details:

    "The Wheel Collider computes friction separately from the rest of physics engine, using a slip-based friction model. This allows for more realistic behaviour but also causes Wheel Colliders to ignore standard Physic Material settings."