PhysicsShapeQueryParamters2D collision detection

Godot Version

4.4.stable.mono

Question

When setting up custom collision, the PhysicsShapeQueryParameters2D class lets you assign the collision mask, but not the layer. Why is this? Is there a way around this? According to some documents, everything is defaulted to Layer 1.

I have a bullet sprite scene set up with the Shape2d collision generated from code, which works correctly against enemies with an Area2d node. However, I have an enemy sprite scene that is set up the same as the bullet, except they won’t detect each other.

There’s practically no information on this sort of set up. I’m trying to process thousands of bullets/enemies at once, and collision detection is the biggest performance hit. Switching the bullet to the custom collision detection has massively increased performance, so I want to do the same to the enemies if I can.

I think you are confusing shape-casts and collision objects.

Shape-casts/ray-casts don’t have any collision-layers, because they can’t be collided with. They just check if the ray/shape collides with something.
If you want the bullet to collide with your enemy, you have to attach/make it a collision object.

If performance is a big issue, you could try to query the PhysicsServer directly. But I would start with attaching simple Area2Ds to the enemies as you do right now and see how it goes - I’m not even sure if a shape-cast is more performant than area2ds.

It didn’t even occur to me that PhysicsShapeQuery was referencing shapecasts, but I should have known better given the whole setup for it. I feel silly about that.

But yeah, getting the PhysicsServer is what I want to do.