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

**URL:** <https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289>\
**Category:** Questions\
**Created:** [August 23, 2022, 10:27am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289 "2022-08-23T10:27:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [August 23, 2022, 10:27am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/1 "2022-08-23T10:27:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![srzerbetto](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srzerbetto/32/20941_2.png) [@srzerbetto](https://forum.babylonjs.com/u/srzerbetto)\
**Post date:** [August 23, 2022, 1:34pm UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/2 "2022-08-23T13:34:47Z")

</div>

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)](https://playground.babylonjs.com/#TK8AM7)

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

---

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [August 23, 2022, 11:47pm UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/3 "2022-08-23T23:47:33Z")

</div>

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? 😀

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 😀

> **[Babylon.js Playground](https://playground.babylonjs.com/#TK8AM7%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Takemura](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/takemura/32/25836_2.png) [@Takemura](https://forum.babylonjs.com/u/Takemura)\
**Post date:** [August 24, 2022, 9:08am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/4 "2022-08-24T09:08:26Z")

</div>

> [@Rata\_Blanca](#):
>
> Could you please explain why does it stop so much amout of space above that sphere?

You need to set ellipsoid:

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

I edited your playground and its working:

> **[Babylon.js Playground](https://playground.babylonjs.com/#TK8AM7%232)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [August 25, 2022, 12:22am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/5 "2022-08-25T00:22:09Z")

</div>

Omg, sorry. Stupid me. Can I ask you to take a look one more time at this? [https://playground.babylonjs.com/#TK8AM7#4](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? 😀

---

<div class="post-metadata">

**Author:** ![Takemura](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/takemura/32/25836_2.png) [@Takemura](https://forum.babylonjs.com/u/Takemura)\
**Post date:** [August 25, 2022, 8:20am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/6 "2022-08-25T08:20:53Z")

</div>

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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#TK8AM7%235)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [August 25, 2022, 9:41am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/7 "2022-08-25T09:41:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [September 10, 2022, 4:42am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/8 "2022-09-10T04:42:33Z")

</div>

@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](https://playground.babylonjs.com/#TK8AM7#37). The problem with the line:

```auto
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](https://playground.babylonjs.com/#TK8AM7#42). 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.

---

<div class="post-metadata">

**Author:** ![Takemura](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/takemura/32/25836_2.png) [@Takemura](https://forum.babylonjs.com/u/Takemura)\
**Post date:** [September 10, 2022, 11:12am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/9 "2022-09-10T11:12:39Z")

</div>

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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#TK8AM7%2343)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#TK8AM7%2344)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Rata\_Blanca](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/rata_blanca/32/24779_2.png) [@Rata\_Blanca](https://forum.babylonjs.com/u/Rata_Blanca)\
**Post date:** [September 10, 2022, 12:03pm UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/10 "2022-09-10T12:03:53Z")

</div>

> [@Takemura](#):
>
> Regard scaling, it is pretty much like above, you have negative Y scaling on meshes[1]

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 😀 Tried to set positive scaling but looks now both checkCollisions don’t work 😀 Ok, now I know the negative Y-scale is the root of my problems, thanks for that!

> **[Babylon.js Playground](https://playground.babylonjs.com/#TK8AM7%2349)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [September 12, 2022, 8:15am UTC](https://forum.babylonjs.com/t/checkcollisions-cant-be-used-with-createinstance-method/33289/11 "2022-09-12T08:15:18Z")

</div>

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](https://forum.babylonjs.com/t/left-and-right-handed-shenanagins/17049)

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