Search Unity

Wheel Collider Slip Effects

Discussion in 'Physics' started by Sethtek_Dev, Mar 6, 2018.

  1. Sethtek_Dev

    Sethtek_Dev

    Joined:
    Feb 4, 2017
    Posts:
    44
    Hello.
    I've been searching but I can't find something that works for me.

    How can I instantiate and play a sound when a WheelCollider is slipping?
    Then once the AudioSource is instantiated, how can I make the pitch match the slip value?

    It's quite confusing to me. :/
     
  2. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
  3. Sethtek_Dev

    Sethtek_Dev

    Joined:
    Feb 4, 2017
    Posts:
    44
    Thank you for the reply but it didn't work.
    upload_2018-3-12_2-28-36.png
    These are the errors and this is my code.
    Since my script is in C# and the code here is in JS. I tried to convert it.
    Code (CSharp):
    1. if (wheel.GetGroundHit (hit))
    2.             {
    3.                 if (hit.sidewaysSlip > 0.5)
    4.                 {
    5.                     Debug.Log ("WHEEL SLIPPING");
    6.                     wheel.GetComponent<AudioSource> ().pitch = hit.sidewaysSlip;
    7.                 }
    8.             }
    I don't really understand it.
     
  4. NDSno1

    NDSno1

    Joined:
    Dec 20, 2014
    Posts:
    223
    Your syntax is incorrect. In c sharp you need out hit, like this:
    Code (CSharp):
    1. if (wheel.GetGroundHit (out hit))
    I think the documentation for this is really bad.

    I would say you should take a look at the vehicle example from the standard asset, they have everything you need to get started on an arcade racing game, including the slip effect you want.
     
    Sethtek_Dev likes this.
  5. Sethtek_Dev

    Sethtek_Dev

    Joined:
    Feb 4, 2017
    Posts:
    44
    Thanks for your help. I had to make some adjustments and it works just fine now ;)
     
  6. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    This helped me a lot too! I didn't know this was this easy. I was prepared to use ray distance checks everywhere along with custom value comparisons... ;_;
     
    Sethtek_Dev likes this.