Search Unity

Wheel Collider Detect Tire Slip

Discussion in 'Physics' started by allencook200, Apr 16, 2021.

  1. allencook200

    allencook200

    Joined:
    Oct 2, 2020
    Posts:
    178
    You know in racing games how if your tire spins underneath you, it creates smoke? And if your car goes sideways, the tires screech and you get smoke too? Is there any easy way for detecting this type of behavior with wheel colliders?
     
  2. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    You can get the slip information from something like this:

    Code (CSharp):
    1. yourWheelCollider.GetGroundHit(out WheelHit wheelData);
    2. slipLat = wheelData.sidewaysSlip;
    3. slipLong = wheelData.forwardSlip;
    Check the documentation here: https://docs.unity3d.com/ScriptReference/WheelHit.html

    sidewaysSlip outputs in radians from wheel direction, so a value of Pi/2 means a pure lateral slide.
    forwardSlip is a % of transmissible force on the slip axis.
     
    Last edited: Sep 7, 2022
    NickelVfiveCENTS and Patrykm1 like this.
  3. GameManiacs

    GameManiacs

    Joined:
    Sep 20, 2020
    Posts:
    5
    I have a simple simple solution for this. By this your car can have skid marks and tire smoke at the right moment
    Code (CSharp):
    1.  WheelHit hit = new WheelHit();
    2.  
    3. WheelCollider yourWheelcollider = GetComponent<WheelCollider>();
    4.  
    5.         if (yourWheelcollider.GetGroundHit(out hit))
    6.         {
    7.             if (hit.sidewaysSlip > .15)
    8.                 Debug.Log("drifting");
    9.         }
     
    NickelVfiveCENTS likes this.