# RayCast ignores faces from mesh

**URL:** <https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408>\
**Category:** Questions\
**Created:** [September 12, 2024, 4:26pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408 "2024-09-12T16:26:17Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 4:26pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/1 "2024-09-12T16:26:17Z")

</div>

hi for everyone, i have this situation:

the box are a primitive in blender, the box is a collider mesh, in fact the bullets againts plane works correctly:  
in bulklet update

```auto
switch (big_enemy.which) {

        case BIG_ENEMIES.jump_gate:

          _distance = utils.distanceInPlane(this.box.position.x,this.box.position.z,big_enemy.mesh.position.x,big_enemy.mesh.position.z);

          if( _distance < big_enemy.radio ){
            //collider fisico
            // let _coll = scenes[this.parent_scene].getMeshByName("red_jump_gate_collider");
            // let _door = scenes[this.parent_scene].getMeshByName("red_jump_gate_door");
            
            // big_enemy.mesh_collider.computeWorldMatrix(true);
            // const pickResulta = this.ray.intersectsMesh(_coll);
            const pickResulta = this.ray.intersectsMesh(big_enemy.mesh_collider,false);
            if (pickResulta.hit) {
              console.log( this.name, "contra big enemy collider" );               
              this.runSparksWithCenter(pickResulta.pickedPoint,Game.ELEMENT_SHIP_ENEMY);
              this.dead();
            }
            

            if( this.mode ){
               big_enemy.mesh_door.computeWorldMatrix(true);
              const pickResult = this.ray.intersectsMesh(big_enemy.mesh_door,true);
              if (pickResult.hit) {
                console.log( this.name, "contra big enemy door" );
                this.dead();
              }
            }
             
            
          }

        break;
}

```

 ![erty](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/4/44c4fecd7d1718fdd63b837ff352570b28d3e6d7.png)

i tried using :

`big_enemy.mesh_collider.computeWorldMatrix(true);`  
before than ray cast

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 4:47pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/2 "2024-09-12T16:47:48Z")

</div>

I rotated 180 degrees the box in blender, and export, however in babylonjs only 1 face is detected by ray :

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [September 12, 2024, 5:06pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/3 "2024-09-12T17:06:06Z")

</div>

It is hard to help without a repro…

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 6:20pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/4 "2024-09-12T18:20:42Z")

</div>

more strange :

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 6:21pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/5 "2024-09-12T18:21:36Z")

</div>

The error is obvious, loading a very similar situation could take me days

---

<div class="post-metadata">

**Author:** ![j-te](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/j-te/32/37194_2.png) [@j-te](https://forum.babylonjs.com/u/j-te)\
**Post date:** [September 12, 2024, 6:45pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/6 "2024-09-12T18:45:29Z")

</div>

You really need to help us help you with a playground repro. If you cannot easily set this up then it shows you need to do more debugging. A lot of the times you find the solution in the playground yourself 🙂

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 7:31pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/7 "2024-09-12T19:31:19Z")

</div>

againts all tanker elements the ray works correctly, same tecnique, againt the jumpgate fails with a single collidert mesh, the unique difference id that the jumpgate can appear in random position around station and rotates looking at station, no more

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 8:17pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/8 "2024-09-12T20:17:55Z")

</div>

Here works, but really many elements are different or not exist in PG :

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

\*click to shoot

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 8:50pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/9 "2024-09-12T20:50:57Z")

</div>

yes sr, you are right, I apologize to everyone 😓

_the jump gate check radius was very low (1.3, now it’s 8.0), so only bullets very close to the center of the jump gate were analyzed. (this is an optimization, to ONLY validate that bullets crossing close to an object are checked if they collided with that object)_

```auto
class Bullet (){

//...
update (){
switch (big_enemy.which) {

        case BIG_ENEMIES.jump_gate:

          _distance = utils.distanceInPlane(this.box.position.x,this.box.position.z,big_enemy.mesh.position.x,big_enemy.mesh.position.z);

          if( _distance < big_enemy.radio ){//big enemy radio had a value of 1.3, very close to jump gate
            //collider fisico
            // console.log( this.name,"contra collider" );
            // let _coll = scenes[this.parent_scene].getMeshByName("red_jump_gate_collider");
            // let _door = scenes[this.parent_scene].getMeshByName("red_jump_gate_door");
            this.box.computeWorldMatrix(true);
            big_enemy.mesh_collider.computeWorldMatrix(true);
            // const pickResulta = this.ray.intersectsMesh(_coll);
            const pickResulta = this.ray.intersectsMesh(big_enemy.mesh_collider,false);
            if (pickResulta.hit) {
              console.log( this.name, "contra big enemy collider" );               
              this.runSparksWithCenter(pickResulta.pickedPoint,Game.ELEMENT_SHIP_ENEMY);
              this.dead();
            }
            

            if( this.mode ){
              big_enemy.mesh_door.computeWorldMatrix(true);
              const pickResult = this.ray.intersectsMesh(big_enemy.mesh_door,true);
              if (pickResult.hit) {
                console.log( this.name, "contra big enemy door" );
                this.dead();
              }
            }
             
            
          }

        break;
}

}
}//end of bullet class

```

---

<div class="post-metadata">

**Author:** ![bitmo\_games](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bitmo_games/32/37337_2.png) [@bitmo\_games](https://forum.babylonjs.com/u/bitmo_games)\
**Post date:** [September 12, 2024, 8:58pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/10 "2024-09-12T20:58:04Z")

</div>

If anyone is interested, here there an implementation with radio\_close enabled, to 8.0 in this case :

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

---

<div class="post-metadata">

**Author:** ![j-te](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/j-te/32/37194_2.png) [@j-te](https://forum.babylonjs.com/u/j-te)\
**Post date:** [September 12, 2024, 9:11pm UTC](https://forum.babylonjs.com/t/raycast-ignores-faces-from-mesh/53408/11 "2024-09-12T21:11:05Z")

</div>

Sometimes it takes a different approach to problem solving, or to have a break and go for a walk/nap 😃 your project looks interesting, keep up the great work! Glad you resolved the issue.
