Detect on which layer a collision occured

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

Hello !
I’ve got players, missile and obstacles in my game.
In order to have a bunch of modes in my game, I want to code in a modular way. That’s why I’ve got :
1 layer/mask for objects which kill the player
1 layer/mask for objects which are destroyed by the player when they touches
1 layer/mask for normal collisions with the player

My question is : is it possible to know which layer triggered the collision ?

Thank you.

:bust_in_silhouette: Reply From: Wakatta

On the CollisionObject you can call collider.get_collision_layer()

Note: if your collider exists in multiple layers that the function would return a sum of all layer bits and won’t work.