I have 4 wheel colliders parented to the box collider,
I then attached the script to the parent box collider; And I wanted to whenever box collider hits something to make a sound like following:
OnCollisionEnter(Collision c)
{
Audio.Play();
}
however, it also play the sound when the children wheel colliders hits something, is there a way to exclude out the wheel colliders, but not seperate it from the parent box colliders?
Thanks!
The Collision object that gets passed to OnCollisionEnter has an array called contacts of type ContactPoint. The ContactPoint object has information about both colliders involved in the collision. You could scan this contact points array, and only play the sound if the box collider is involved anywhere. Not ideal, I know, but the Collision object itself unfortunately doesn’t contain information about both colliders.
oh wow, thanks. But that’s the only way to do this? Let me just make sure, the points that I am going through are not all the points on collusion mesh, but only points that have hit during the updated frame, then I would going through the loop and check if none of those points are the box collider,then I won’t be playing the box hitting sounds, other wise if contact points has both, I would assume wheel colliders and box colliders hit something.