0 votes

I have an Area2D (a character) who has several collisions shapes, one for his body, one is a large circle around him which is its range to detect object.

Is it possible to put each collision shape in a different layer object? Because I want the first collision shape to only collide with other characters, and the second one to only collide with objects (another node of type Area2D).

Unless, the only solution is to distinguish collisions (process some and ignore others) in the code? Because as far as I know, only an area2D can have a collision layer, not his collisions shapes.

Or maybe, it's good practice to define the node tree like this?

Area2D (Character)
--Area2D (to detect other characters)
---- CollisionShape
--Area2D (to detect objects)
---- Collision Shape

instead of

Area2D
--Collision1
--Collision2

Which is the best solution?

asked Sep 8, 2019 in Engine by x4rkz (35 points)

1 Answer

+1 vote

Multiple collision shapes on one Area2D still define only one area, so they will act like one large one.

If you want the shapes to have different functionality, then yes, you need them to be separate Area2D nodes. These can then be put on different collision layers, have different code for area_entered, etc.

answered Sep 8, 2019 by kidscancode (13,384 points)

Then I should do something like this?

Area2D (Character)
--Area2D (to detect other characters)
---- CollisionShape
--Area2D (to detect objects)
---- Collision Shape

Unless the first node does not have to be an Area2D? If so, what else could I choose? A Node2D?

After some thinking, it might be better to do

Scene
-- Area2D
---- CollisionShape
---- Sprite
-- Area2D
---- Collision Shape

what do you think ?

What you choose for your root node depends on what you want it to do. In your example, it could be the Sprite. If it needs collision, maybe a KinematicBody2D, etc. Try it a few ways and see what makes the most sense for your needs.

Okay but it is still unclear to me if I need can do this:

Scene
-- Area2D
---- CollisionShape
---- Sprite
-- Area2D
---- Collision Shape

Or if I need a wrapper like this:

Scene
-- Area2D (or KinematicBody or Sprite or anything)
---- Area2D
------ CollisionShape
------ Sprite
---- Area2D
------ Collision Shape

Well, there's no point in yet another Area2D node without a shape or anything. Why not this:

Area2D (main)
---- Sprite
---- CollisionShape2D
---- Area2D (secondary)
-------- CollisionShape2D

You move the main Area2D that the Sprite is a child of, and everything else comes along. No need for extra nodes that don't serve a purpose.

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 How to use this Q&A? before posting your first questions.