Masks and Layers not working as stated in the documentation

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Thenend

· collision_layer
This describes the layers that the object appears in. By default, all bodies are on layer 1.
· collision_mask
This describes what layers the body will scan for collisions. If an object isn’t in one of the mask layers, the body will ignore it. By default, all bodies scan layer 1.

As far as I understand, according to the documentation, if you test for collisions, for example using “move_and_collide”, the system will report collisions with bodies that are in a collision layer that is in the collision mask of the object we are calling the function on.

However, that is not always true.

Collisions are also detected against an object that happens to be looking for a mask that the object that is checking for collisions is in.

For example, you can have an object that is in no layer, but is testing for the player mask. Then, the player (that of course is in the player mask), is going to collide against that object when executing move_and_collide.

Is this the intended behaviour?

If it is, that’s not what I understand from the docs.

enter image description here

EDIT: forums are confusing

devguydan | 2020-11-30 20:30

:bust_in_silhouette: Reply From: deaton64

Yes I believe you are correct. Adding a collision detection from one object to another, is like you’ve done it in both. Don’t add it to the collision layer.
Here’s a good video about collision: Using Physics Layers and Masks in Godot 3.1 (tutorial)


In that case, I think it should be corrected in the documentation. While searching around I found much confussion with this behaviour.

I’m really liking Godot as a tool, but bugs in very basic funtionality and misleading documentation are keeping me away from recommending it to other developers :frowning:

Thenend | 2020-06-05 11:33

:bust_in_silhouette: Reply From: devguydan

I ran into the same behavior. The docs state that the mask determines which bodies will be scanned for. I have a hurt/hit box system. If I set the mask for the hurtbox to nothing, but set the mask for the hitbox to scan for hurtboxes, then the hurtbox will trigger collisions even though it’s mask is completely blank. If the documentation was correct I would expect that only the hitbox would trigger collisions since it is the body with the mask that scans for hurtboxes. The hurtboxes should not trigger any collisions if its mask is turned off.

The current behaviour basically says, if body A is scanning for body B, then body B will also scan for body A even though it is not set to do so.

This could lead to really confusing behavior if I set the mask of body A to scan for body B and the mask for body B to scan for body C. Then when body B experiences a collision, I would expect that it MUST be body C since that is what my mask is set to. But in fact it may be body A OR B, even though I told body B to only scan for body C.