Search Unity

Question about WheelCollilder - vehicle not going straight

Discussion in 'Editor & General Support' started by vegardw, Oct 3, 2010.

  1. vegardw

    vegardw

    Joined:
    Oct 2, 2010
    Posts:
    3
    New Unity user here, playing around with Wheel Colliders.

    I've made a simple "vehicle" consisting of a resized "Cube" GameObject with 4 empty child objects with WheelCollider components attached, one in each corner of the vehicle. The vehicle is situated on a plane:



    I've the made a small script that sets the motorTorque on the two rear wheels, and the vehicle moves forward, as expected. However, it doesn't move in a straight line, but turns slightly to the left. Everything is set up symmetrically on the vehicle, and the plane is level. Shouldn't the vehicle then run in a straight line?

    My controller script (C#):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class BasicCarController : MonoBehaviour
    5. {
    6.  
    7.     // Private member variables
    8.     private WheelCollider[] wheelColliders;
    9.    
    10.    
    11.     void Start()
    12.     {
    13.         wheelColliders = new WheelCollider[4];
    14.         wheelColliders[0] = gameObject.transform.Find("Wheels/FrontLeft").GetComponent<WheelCollider>();
    15.         wheelColliders[1] = gameObject.transform.Find("Wheels/FrontRight").GetComponent<WheelCollider>();
    16.         wheelColliders[2] = gameObject.transform.Find("Wheels/RearLeft").GetComponent<WheelCollider>();
    17.         wheelColliders[3] = gameObject.transform.Find("Wheels/RearRight").GetComponent<WheelCollider>();
    18.     }
    19.    
    20.     void FixedUpdate()
    21.     {
    22.         wheelColliders[2].motorTorque = 15;
    23.         wheelColliders[3].motorTorque = 15;
    24.     }
    25. }
    26.  
    The Project can be downloaded from
    http://debian1.vegardw.com/WheelColliderTest/WheelColliderTest.zip

    Webplayer showing the vehicle turning at
    http://debian1.vegardw.com/WheelColliderTest/WebPlayer/WebPlayer.html
     
  2. vegardw

    vegardw

    Joined:
    Oct 2, 2010
    Posts:
    3
  3. bitbutter

    bitbutter

    Joined:
    Jul 19, 2012
    Posts:
    60
    The reason for the drifting seems to be some kind of bug related to fixed timestep. The drifting can be removed by reducing the timestep, see animated gif below for a before and after.

    $R6Awab6.gif
     
  4. mustafaguven

    mustafaguven

    Joined:
    Oct 17, 2013
    Posts:
    3
    Yes, it fixed thank you but I wonder that would this adjustment ruin any other settings? Did you check it?
     
  5. Visual-Arts

    Visual-Arts

    Joined:
    Oct 28, 2017
    Posts:
    4
    Hello everyone! I have the same problem in my game! I tried to do like this but I couldn't fix the problem! My vehicle not going straight! How can I fix that! You can also watch at this video!
    First video >>>
    <<<
    Second video >>>
    << bandicam 2017-10-28 22-07-18-633.jpg bandicam 2017-10-28 22-09-31-287.jpg bandicam 2017-10-28 22-07-18-633.jpg bandicam 2017-10-28 22-09-31-287.jpg
    How can I fix that problem! Your posts didn't helped me to fix that problem!