Hello I have a problem with collision event using coumpound physics shapes.
(I’m working on a flight simulator project, and I would like to play a sound each time a tire touch the ground)
I am new so i am not sure I would be able to help. But I think the thing that you are doing wrong is that you consider that all 4 legs will trigger the start collision. The thing that is happening is that your whole chair is being treated as a single rigidBody with 1 collision detection. So you are getting 2 because 1 is for the initial hit that the body hits the ground. The second hit comes when the chair bounces and hits again. If you want it to detect 4 collision on each leg then you would have to attach the collision script as well as the rigidBody and collision components to all of your legs.
I think the best way to approach that would be that add rigidBody and collision to each of the child components of the chair but not the chair entity. Then you can have another script attach to chair entity by which you can get the sum of hits of all the Childs.
Well, specifically for this model, it may have dozens of points. Each vertex on each leg touching the floor will generate a contact. Since the bottom of the leg consists of many vertices, each leg may have multiple contacts.
Edit:
You can see how Ammo detects contacts using the Debug Drawer. It draws the contact point normal for each vertex generating a contact. The reason the contacts change is because of the way Ammo solves the collision. https://playcanvas.com/editor/scene/1169174
@MHA : I tried that but it doesn’t work with coumpound physics shapes collision : if I add rigidBody & collision to the chair… the chair parts become free to move independently => the chair is broken … and reading the one of the @yaustar answer in this forum thread (https://forum.playcanvas.com/t/where-can-i-find-documentation-for-the-compound-collider/16177/5), I understand that the way the coumpound physics shapes collision works imply that you don’t add rigidbody to child physics shapes collision :
"That would be an incorrect setup as only the parent entity should be set as either a rigidBody or just a collider (trigger). The children should only have collider components that define the shape of the compound "
As @MHA mentioned, the compound collider will fire a collision start event as a single body. It means, that a new collision start event will be fired, only if the previous one ended. If the body keeps touching the floor with some part, it will not trigger new events.
Not sure if there is an easy way without some custom logic that is specific to your model. As Ammo is concerned, it is just a bunch of vertices - it will report whichever is touching the ground, but it is then up to you to decide if it is a new collision or not.
I just did some basic stuff but I think I might have done the thing that you want to accomplish. Tell me if it helped you. I have not made the whole chair but just 4 legs. Hope you figure out the rest if I am right.
thks @LeXXik for your project and and explanations… I understand now much more better what is happening ! thks also @MHA… I think it would solve my problem to be able to to attach the collision script to each leg… but it’s not working unfortunately
I have modified the example project so it’s look like more what I’m looking for (I replaced the chair by an aircraft with 3 wheels. I’m will try tonight to go ahead from there !