How can i get the collision layer or mask of a body

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

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?

:bust_in_silhouette: Reply From: Wakatta

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
layer1_value = 2, layer5_value=16
var layer = body.get_collision_layer() #would return 18