Error with collider

i have this behaviour, someone had seen it :

*I haven’t created the playground yet because I have many lines of code to implement correctly in PG, first I want to know if it has happened to anyone.

the model is in .OBJ and i tried with gltf (keeping x pos =0)

the scale of model, main and collider is ok, i used same config collider for other things and works fine…

in update of all bullets :

if( big_enemy != null ){

        switch (big_enemy.name) {

          case 'jump_gate_red':

          break;

          case 'jump_gate_green':
            
          break;

          case 'big_enemy_cruiser':
            // console.log( 44444 );
            _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("crucero_collider");
              
              if( this.mode ){
                // if (this.box.intersectsMesh(_coll, PRECISION_INTERSECTS_MESH)) {  
                if (scenes[this.parent_scene].getMeshByName("crucero_collider").intersectsPoint(this.box.position, PRECISION_INTERSECTS_MESH)) {                         
                  // big_enemy.makeHurt(this.damage,Game.ELEMENT_BULLET,this.box.position);
                  this.runSparks(Game.ELEMENT_SHIP_ENEMY);
                  this.dead();
                }
              }
              
            }

          break;
        
        }//end of which boss

        

      }//end coll big enemy

I don’t see the questoin here :smiley:

I deciphered your “question”/watched the video and got to the conclusion that the bullets are not colliding with the ship correctly when it is loaded from a glb? hm?

glb or obj, fails same
i tried frist with glb, i thouht that the problem with xAxis inverted was the cause, but not …

Visualize your colliders using

const viewer = new BABYLON.Debug.PhysicsViewer(scene);
viewer.showBody(mesh.physicsBody);

EDIT:
Or you don’t use the physics engine? — just peeked at your code… seems you don’t

but, i want to use my custom collider :
i created it on blender :

Are you testing the mesh intersections against this collider mesh? ì suppose you do.

i used engine for other meshes, when ship fall to planet… but the physics engine has instantiated in scene…

yes sr, in bulet update :

case 'big_enemy_cruiser':
            // console.log( 44444 );
            _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("crucero_collider");
              
              if( this.mode ){
                // if (this.box.intersectsMesh(_coll, PRECISION_INTERSECTS_MESH)) {  
                if (scenes[this.parent_scene].getMeshByName("crucero_collider").intersectsPoint(this.box.position, PRECISION_INTERSECTS_MESH)) {                         
                  // big_enemy.makeHurt(this.damage,Game.ELEMENT_BULLET,this.box.position);
                  this.runSparks(Game.ELEMENT_SHIP_ENEMY);
                  this.dead();
                }
              }
              
            }

          break;

Can you post the collider glb file here?

really i preffer use obj, (gltf/glb has a problem with X axis), i tried with that because with obj i need create manually the relations, but i created it now

obj :
https://testpiers.sfo3.cdn.digitaloceanspaces.com/spi/crucero.obj
mtl :
https://testpiers.sfo3.cdn.digitaloceanspaces.com/spi/crucero.mtl

mm, all childrens are in pos 0,0,0 because to create manually relations is better.

in glb :

https://testpiers.sfo3.cdn.digitaloceanspaces.com/spi/crucero2.glb

PRECISION_INTERSECTS_MESH const is true value.

image

the glb has non uniform scaling and not 1

I fixed the scaling but it still collides far away from thr actual collider:

Now let me check you colliding code:

first issue is: .intersectsPoint(this.box.position, PRECISION_INTERSECTS_MESH) requires only one parameter

EDIT;

This works but it’s not an optimized and quickest solution. I’ll be back after my sleeping session :smiley:

1 Like

ok many thanks

intersectsPoint uses the bounding box to detect collisions so it’s out of the game.

Look at this example:
https://mugen87.github.io/yuka/examples/math/boundingVolumes/

What you need is ConvexHull collision:

Another approach is to use multiple boundig boxes so instead of one collider mesh you’ll end up with multiple smaller collider meshes. In this case you can use intersectsPoint and loop trough the colliders from the biggest one to the detailed/smallest ones.

Using a full blown mesh just for collisions is an overkill so I would opt for Yuka or write my own collision detection which would create the AABBs (check the Yuka example page once again, select Bounding Volume to AABB to see what am I talking about) from the meshes imported from Blender (you need a tool to place your BBs precisely) and dispose the meshes afterwards.

Maybe there is a plugin for Blender which can generate the BBs for you.

Talking about YUKA you could use a lot of other stuff from the library for your game :wink:

2 Likes

Soved, i attach a small ray in front of bullet :

to keep good optimization i reduced the use of raycasting :

in bullet update :

case 'big_enemy_cruiser':
            
    _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("crucero_collider");
      
      if( this.mode ){
        
        const pickResult = this.ray.intersectsMesh(_coll);
        if (pickResult.hit) {  
          // console.log( "hit" );
          // console.log( pickResult );
          // this.runSparks(Game.ELEMENT_SHIP_ENEMY);
          this.runSparksWithCenter(pickResult.pickedPoint,Game.ELEMENT_SHIP_ENEMY);
          this.dead();
        }
      }
      
    }

  break;

i saw yuka, for this project, is too big, but it is awesome maybe in the future i can consider it :slight_smile:

intersectsMesh will be much slower then linked AABB checking.

yes sr, but i need precision :

Did you miss this?

You first check against the big red BB. If it misses you continue to the next bullet. If it hits, you test all the children BBs of the parent BB. For example you can have two children BBs. You will hit one of them. Then you check against its children BBs to the detail level as you want. This is blazingly fast.

I saw it, for now I will continue with my custom collider, I did it with low triangles, if I see some low speed fps I will try your approach.

The cruiser is static, the bullets test collider less times per second than FPS rendering.

this is a big project, with low resources (money and time) so i need to take quickly choices