Search Unity

Wheel Collider Acceleration WAY TOO SLOW

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

  1. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    140
    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:
    290
  3. PixelCloudInc

    PixelCloudInc

    Joined:
    Dec 26, 2017
    Posts:
    140