Checking ray collision against one subnode

Hi, recently i’ve been struggling to fix my hitboxes whenever a player shoots with a raycast weapon. The scene setup is:

At the moment, the shooting invokes:

var results = ...;
var mobNode = ...;
shotRay.collideWith(mobNode, results);

Given my setup, the ray checks collision against both hitboxes attached to the armature and against the model itself (in its static pose). This creates 2 issues:

a) hits sometimes registering when they shouldnt (when the ray collides with the model itself)
b) collision is fairly expensive, as models can get complex for bigger enemies

I cannot come up with a way to only check the collision with hitboxes attached to the armature without moving the model to a completely separate node and “manually” syncing the armature position with the model position. Will appreciate any tiny bit of help :frowning:

I use attachment nodes for hitboxes in a similar way for my game, and the way I do it is by keeping a list of each mob’s hitboxes in the “Mob” class.

Then, instead of colliding with the “mobNode” you could call a collision method in the “Mob” class where you would loop through the list of hitBoxes for that mob and collide with each individually.

Something like:

public class Mob{

   ArrayList<Geometry> hitBoxGeos;
   Node mobNode;

   public void setUpHitBoxes(){
        hitBoxGeo1 = makeOrFindHitBoxGeo();  //make a method like this to find/create each hitbox
        hitBoxGeos.add(hitBoxGeo1);


   }
   public boolean collideWithMobsHitBoxes(Collidable colliable){
         for(Geometry geo : hitBoxGeos){
               //collide each geo with colliable and return true if collision happens
         }

    }

}
2 Likes

i see, thanks. But how do you know which mob to try to check collision against (do you do any broad phase collision)? Or do you iterate over each and every mob?

I iterate over a list of all living mobs.

And, to keep it optimizeed, i first do a .intersects() check between the ray and each mobs BoundingVolume before colliding against the hifboxes to make sure im not wasting resources doing an expensive geometry collision unless i know they already intersect (since checking intersection between a bounding volume and ray is much faster than full collosions between rays and geometries).