CheckCollisions can't be used with createInstance() method?

I load my mode with importMesh() (.glb, just a cube, collisions attached in Blender as RigidBody), then I create two instances of just loaded mesh with: createInstance() and set checkCollisions = true for all three objects and trying to check it with moveWithCollisions().
Only the original mesh works correctly with collisions. Instances allow go through its bounding box.

Using clone() instead of createInstance() works perfectly for all the copies.

Is that known behaviour or am I doing something wrong?

Hi @Rata_Blanca , how are you doing?

As far as I know, collisions should work with instances. I did a small playground example, and it is working fine: Babylon.js Playground (babylonjs.com)

Maybe it is something related to the way you are configuring it.
Can you share a playground example that shows your scenario?

1 Like

Thanks for the reply! Hm, ok. I’ve added some mesh to your demo. Could you please explain why does it stop so much amout of space above that sphere? I think collision boxes don’t move with its instances.

Shouldn’t collision boxes move with its instances? Is there a way to move collision box manually? :grinning:

Anyway I can create another cube/capsule to get collision box from it and make that mesh isVisible=false, so I will not add one more draw call, at least, but I will get the collision box. Then just move it along that instanced mesh or parent instanced mesh to invisible collision mesh, but as you understand it’s not the greatest solution :grinning:

You need to set ellipsoid:

playerMesh.ellipsoid = new BABYLON.Vector3(.5, .5, .5);

I edited your playground and its working:

3 Likes

Omg, sorry. Stupid me. Can I ask you to take a look one more time at this? https://playground.babylonjs.com/#TK8AM7#4

I think it’s the root of my problem. In my project I see ablosutely the same weird behaviour. look at the speed when it’s colliding. The speed changes automatically by BJS. And it slowly going through the collision box of instanced mesh but it doesn’t go through the original mesh. But look at that broken-collisions case: the capsule never appears below that cube, but why if the capsule goes without any stop, then where is it? It never goes out of the cube, but it continue flying but where is it then? It just stays on the bottom side of the cube don’t know why.

gltf file was created and exported out of the Blender 3.2. Cube has a collision box attached by the Rigid Body (where a collision type was changed from “convex hull” to: “box”).

Am I missed something again? :grinning:

Your root of gltf-file (aka meshes[0]) got negative scaling on z-axis. You need to remove parent from the mesh you create instances from:

meshes[1].setParent(null)

Here is the edited playground:

5 Likes

Wow, you finally got it working! That’s awesome. Thanks a ton!

@Takemura , can you please take a look at this my simple example? I tried to create a collision box for my simple mesh and set it as a parent. When rotate parent mesh it brokes the collision system:

Here I show it on the line #40. The problem with the line:

instancedMesh0.rotationQuaternion = BABYLON.Quaternion.FromEulerAngles( 0, 0, 0 );

Why does it work like this? If I remove this line all works fine.
Maybe I shold call some update method for the instanced mesh when I han applied a rotation to it?

I tried to make a bigger collision box as a separate mesh which will be set as a parent for the origin mesh.

UPD: Seems there are some problems when instanced meshes parented to some another meshes. When they’re not then all works fine with rotating but not when instanced mesh is scaled. When it’s scaled then the problem still stays: playground. Even if it’s parented to null. Interesting that it doesn’t work for usual meshes as well.
It shows correct bounding box but it goes through it slowly.

Your .gltf-mesh got an rotationQuaternion of (0, 0, 1, 0).
Then you set parent instance’s rotationQuaternion to (0, 0, 0, 1), so both instancedMeshes rotates, but your parent instance is now on top and you did set collision on it to false, if you set to true it works with rotationQuaternion:

Regard scaling, it is pretty much like above, you have negative Y scaling on meshes[1], then you set to positive 2, this won’t work, it will stick to initial sign, maybe some gltf-expert like @bghgary or physics guru @Cedric knows where this is defined. But with your current gltf, it works with -2 for y-scaling:

1 Like

Omg, I didn’t know that my model has scaleY=-1. I exported it from Blender. In Blender it had positive scale values.
Can I fix such models in runtime when the model loads? I don’t wanna work with such weird numbers :grinning: Tried to set positive scaling but looks now both checkCollisions don’t work :grinning: Ok, now I know the negative Y-scale is the root of my problems, thanks for that!

You can switch the scene to use right handed coordinate system. There are some thread on this forum like this one : Left and Right Handed shenanagins

Basically, you just have to add :
scene.useRightHandedSystem = true;

2 Likes