0 votes

I've been following tutorials on how to use bit layer-mask, but none of it seems to work.. Here's my setup:

layer:  bit3=1
mask:   bit4=1


#enemy (not working)
layer: bit4=1
mask:  none

#enemy (not working)
layer: bit3=1, bit4=1
mask:  none

#enemy (not working)
layer: bit3=1, bit4=1
mask:  bit3=1

#enemy (not working)
layer: bit3=1, bit4=1
mask:  bit4=1

It's supposed to print out a statement when the area collide. The statement never printed for any of these configurations.

The only setup that works is when I turn on both bit 3 and 4 of the enemy's mask:

#enemy (working)
layer: none
mask:  bit3=1, bit4=1    #BOTH bits must be high. why?

and yes, both bit 3 AND 4 must be active for the collision to be detected. if either bits is pulled down to 0 then the collision will not be detected and no print statement will occur.

Did Godot4 change how layer and bitmasking work or is this a bug? Where do I go to see known bugs? I'd like to report it if it's actually a bug.

Here's the code for the enemy if it helps btw:

func _on_hurtbox_area_entered(area):
  for body in $hurtbox.get_overlapping_bodies():
Godot version Gadot_v4_alpha14_win64
in Engine by (34 points)
edited by

1 Answer

+1 vote
Best answer

IIRC Godot 4.0 does change logic behind collision layers. While in 3.x you can use layers and masks interchangeably, in 4.0 layer decides can the body be collided with (ie. world should always be on layer) and mask decides if the body can collide with objects in that layer (ie. player and enemy colliders should have mask set, and layer only if they should collide with each other). This system is more flexible, and for me at least, more intuitive.

Same logic goes with areas. Since you want player to be noticed, it should be in layer (in this case, it is on layer 3). Enemy hurtbox should have corresponding mask active. Looking at your examples, enemy 3 should also work, so I'm not sure what's going on there. I recreated scene as such and it worked. Try investigating your setup a bit more or recreating experiment with smaller scale. Maybe enemy has collider which doesn't allow it's hurtbox to overlap with player?

by (810 points)
selected by

Ahhh. I finally found the problem. It was the line getoverlappingbodies().

The interacting nodes were areas, not bodies so I had to use getoverlappingareas() instead. Thanks for the help

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.