I got this FPS project where the player turns to a ragdoll when he get hit by an object, and then fall to the ground. How do I apply sound to the ragdoll when it fall on the ground? Or how do I add sounds for the ragdoll tumbling down a hill? Do I check the collision for each collider on the ragdoll with the ground/hitting object, and if the impact is high enough play a sound? Never done anything like it, I don’t even know where to begin to approach it. Any help would be appreciated!
That’s pretty much what I do. I have a script on each of the rigidbodies that handles OnCollisionEnter, and then basically just passes the collision to the Ragdoll’s script, to its HandleCollision method:
public void HandleCollision(Collision collision)
{
if (_timeSinceLastThud > 0.2f
&& collision.relativeVelocity.sqrMagnitude > 4
&& collision.gameObject.transform.root != transform.root)
{
_timeSinceLastThud = 0;
AudioDirector.Instance.PlayPooledAudioClipAtPosition(PlayerDeathRagdollAudioSettings.ThudAudioClipDefinitions, this.transform.position);
}
}
This approach does a couple of things:
- It allows you to prevent the impact sound from playing too often, across the whole ragdoll. In this case, I don’t allow more than one thud per 0.2 seconds.
- The impact speed has to be high enough
- The ‘transform.root’ stuff ensure that the different rigidbodies in the ragdoll don’t make noise if they hit each other.
2 Likes
OK! Thanks! I kind of was on the “right” track then. I’ll try and experiment some with that.