So, I have a simple 3D game with a player, an enemy, and walls. I've figured out how to detect collisions between my player (RigidBody) and an enemy or wall (Static Body). I want to know how can I group all the enemies so that the player collision can detect whether it's collided with an enemy or a wall, kind of like tags in Unity?
Godot has groups, that work like Unity tags but are more powerful and versatile.
You can assign nodes to one or more groups, and check for group membership when a collision occurs.
Objects in the same group can belong to different layers. If you don't need layer-based collisions, just use groups; otherwise, Arian Keshvari's answer is the additional way to go.
kind of like tags in unity
that's what you should do in Godot too, but not the tag, rather the layer.
For instance, you can put all of your enemies in a layer named
Enemy or the player in a layer named
Player. It's called
Collision Layer on Godot and the
Collision Mask is just like the
Layer Collision Matrix in Unity and can define which layers can collide with each other.
If you need to know the layer of an object you just have to use this code:
And it can be used to determine further actions like taking damage, interacting with NPCs, opening doors, etc.