3
\$\begingroup\$

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?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Both the answers you got are correct. I have a complete explanation elsewhere. \$\endgroup\$
    – Theraot
    Commented Mar 24, 2022 at 23:22

2 Answers 2

3
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Yes, what I was looking for. \$\endgroup\$
    – Programmer
    Commented Mar 25, 2022 at 19:20
3
\$\begingroup\$

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:

object.get_collision_layer()

And it can be used to determine further actions like taking damage, interacting with NPCs, opening doors, etc.

\$\endgroup\$
1
  • \$\begingroup\$ ok I will keep this in mind \$\endgroup\$
    – Programmer
    Commented Mar 25, 2022 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .