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. :/
You can use WheelHit.sidewaySlip and WheelHit.forwardSlip, then specify the slip amount to start playing sound, and modify the pitch based on these two exposed value. https://docs.unity3d.com/ScriptReference/WheelHit-forwardSlip.html https://docs.unity3d.com/ScriptReference/WheelHit-sidewaysSlip.html
Thank you for the reply but it didn't work. 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): if (wheel.GetGroundHit (hit)) { if (hit.sidewaysSlip > 0.5) { Debug.Log ("WHEEL SLIPPING"); wheel.GetComponent<AudioSource> ().pitch = hit.sidewaysSlip; } } I don't really understand it.
Your syntax is incorrect. In c sharp you need out hit, like this: Code (CSharp): 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.
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... ;_;