RayCast ignores faces from mesh

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

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;
}

i tried using :

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

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

It is hard to help without a repro…

1 Like

more strange :

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

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 :slight_smile:

1 Like

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

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

*click to shoot

yes sr, you are right, I apologize to everyone :sweat:

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)

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
2 Likes

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

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

2 Likes