I’m making a 2D top-down rogue-lite game where the player will navigate a procedural dungeon with rooms of different size interconnected with doors.
I’m at the point where I’m implementing a proper interaction system whereas before, I used simple physic collision on the tilemap which was working fine, but far from optimal.
1st: Player is on Layer 2; as is its Area2D. The latter has mask 3 & 4 active.
2nd: The procedurally generated Area2D comes from a InteractiveArea class containing 4 methods: _on_body_entered/exited and _on_area_entered/exited. Inserted via code. (Show below)
3rd: There is no collision detected. I print() everywhere and there’s nothing triggered inside the procedural Area2D. But it works fine if I mask it on for the door physics collision.
Code
This is the function that creates the procedural Area2D. I’m at the point where I mash the keyboard hoping that what is added will fix the “problem,” but it isn’t working. Obviously. I’ve looked high and low on the interwebs but couldn’t find anything. Or I might just be blind. The Area2D is on Layer 3, as shown below.
I have to be forgetting something, but I need fresh eyes.
Here’s a screenshot of what they look like in-game. The image is self-explanatory. If the player’s Area2D collision detection (orange) hits a door physics collision I get a print output, but nothing with the square at the base of the doors. Nothing from the walls either, but that’s because they’re on a different layer.
This is now working except for one detail. The collision is detected on the player collision rectangle instead of the Area2D I set up for interacting purposes. (see below)
The collision is only detected when the player collision (white arrow) enters the interactive area, but nothing is triggered where the red arrow points to enters the area.
Both the player collision and the player’s Area2D use the same collision layer (2). The player has 1, 3 and 4 as mask whereas the Area2D uses 3, 4 and 8.
The player scene is simple:
(Had to remove because of new user limitation. If needed I can post it in reply.)
I’m not sure where to look to explain why the proper area (orange box) isn’t triggering when they collide or am I misunderstanding how this works?
I’m starting to think I should use something else than an Area2D for the player’s interactive area. In fact, the more I think about this, the more it makes sense.