0 votes

Hey guys!
I need to know which are the layers of a body that collides with a Area2D.
Cuz if a body with a certainly layer enter in that area, it should disable the parent mask of that layer for a sec, because i had two collider that should not collide with a body in that area, but since i can't remove it's collision_mask cuz it's parent have children colliders that must had that mask. And that it's coursing me a bug.

How can i do that through code?

Godot version 3.2.3
in Engine by (75 points)

1 Answer

+1 vote
Best answer

If that body is in only 1 layer then

func _on_Area2D_body_entered(body):
    var layer = body.get_collision_layer()

However if that body is like an onion you're gonna have to get a little mathematical, each layer has a unique value/bit and multiple layers would be a combination of those values/bits

for example
body is in layer1 and layer5
layer1value = 2, layer5value=16
var layer = body.get_collision_layer() #would return 18

by (6,934 points)
selected by
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.