meshImpostor, gltf model passes through other

Hello, everyone. Can you teach me that mesh collision?
I put meshImpostor when loading the model. However, the model always slips past the other model without responding to the collision. Your help would be very appreciated. Thank you.

My code↓

scene.enablePhysics(new BABYLON.Vector3(0,-10,0), new BABYLON.AmmoJSPlugin());
BABYLON.SceneLoader.ImportMesh("", "", "model.gltf", scene, function (newMeshes, particleSystems, skeletons) {
                   newMeshes[0].physicsImpostor = new BABYLON.PhysicsImpostor(newMeshes[0], BABYLON.PhysicsImpostor.MeshImpostor, {mass: 0, restitution: 0.8});
                }

newMeshes[0] is probably not the right mesh. When loading a gltf/glb file, the first “mesh” is in fact a transform node that handles converting from right handed to left handed system. So, try newMeshes[1] instead. If it still does not work, you should provide a repro in the Playground so that people can help.

2 Likes

Yeah, I’m gonna have to agree with @Evgeni_Popov. Another option that you could also look into is adding a mesh to act as a sort of bounding box or collision mesh. Here’s an example: Babylon.js Playground (babylonjs.com)

1 Like

I tested meshImpostor but object passes through other…
…I want objects to move away when they collide :sob:
https://playground.babylonjs.com/#FD65RR#67

aasdf

I think I should use intersectsMesh. You can see that when the ball hits the box, it bounces back.
https://playground.babylonjs.com/#2N6Q9H#4

Object bounces back when it hits another object. But it is not working well…
https://playground.babylonjs.com/#2N6Q9H#10

2 Likes

Adding @Cedric who is a killer with physics!

1 Like

Create an impostor for each mesh, add a static ground…and you are done:
pass through | Babylon.js Playground (babylonjs.com)

3 Likes

Thank you so much. :astonished:
Sorry, but it’s not working in gltf file… Could you teach me? @Cedric
https://playground.babylonjs.com/#FD65RR#67
aasdf

This is improved version imported one by one. But object passes…
https://playground.babylonjs.com/#FD65RR#71

1 Like

You added the drag behavior to just the mesh which doesn’t move the imposters. I changed it to physicsRoot and now it works.

https://playground.babylonjs.com/#FD65RR#72

4 Likes

Thanks, Jedi master!!!

1 Like

Sometime pointerDragBehavior is not working, but I make this with your advice.
You can see my code in this link.
https://app22gtt.s3.ap-northeast-1.amazonaws.com/babylon/shockMesh.html

When the thing I am moving collides with something else, I want it to stop moving without fusing with the other thing. The meshimpostor is a slow process and the bumped object will move, so I decided to use an intersectsMesh to detect collision and stop the movement. I also understood that newmesh[1] can detect an intersectmesh instead of newmesh[0].
I would like to use other advice in the future, such as meshImpostor.

Thank you for all kindness.

test in, but it’s not working well.
https://playground.babylonjs.com/#FD65RR#85

@Cedric might help with the physix part

1 Like

I appreciate all of your advice. But, physix is too difficult for me…

You can check my program in this link. It’s not working well…
https://app22gtt.s3.ap-northeast-1.amazonaws.com/babylon/shockMesh1.html

My gltf file is here…
https://app22gtt.s3.ap-northeast-1.amazonaws.com/babylon/model.zip

Would be great if you could setup the repro in the playground :slight_smile:

1 Like

intersectsMesh version_working, but kitchen react when you touch to the vacant space of others.
https://playground.babylonjs.com/#2MR5C0#2

physicsImpostor version_not working well
https://playground.babylonjs.com/#9UTS7C#3

My goal is to do things which hit that don’t move and things that don’t overlap.

A mesh impostor can only be static (with mass == 0). If you want to move a more complex object, you should use compound objects :

1 Like