I’m currently doing the sound design for a small racing game built in unity. I’m having some trouble getting different terrain types e.g. grass, sand, to trigger loops on entering. The car is using wheel colliders, and all different terrains are made of both ‘Default (Mesh Filter)’ and ‘Mesh Renderer’ components. How can I make things respond to these different terrain types? I’ve never really used unity so I’m a bit out my depth - any help would be really appreciated!
You need to do this from scripting.
- WheelCollider.GetGroundHit returns a WheelHit struct with the contact information.
- WheelHit.collider is the collider the wheel is contacting with.
- You may query Collider.sharedMaterial for the actual material assigned to the contacted collider.
- Based on the collider and/or material you can then modify the friction properties of the WheelCollider: WheelCollider.forwardFriction and WheelCollider.sidewaysFriction.
- The easiest way is just modifying WheelFrictionCurve.stiffness. You may simply assign it to the material’s coefficient of friction: PhysicMaterial.dynamicFriction.