I'm new to Godot, and came across an issue. Maybe I'm going about this the wrong way or I'm unaware of something.
I'm procedurally generating levels/maps. I display one "room" of the level at a time. Each room is rendered "top down" using a TileMap.
I have door triggers in the form of Area2D-based scenes with a CollisionShape2D child. I spawn them at the appropriate locations based on the room. I do this by converting what would be the tilemap location to the world location.
A lot of the time, everything works just fine: When my character overlaps with one of the above door triggers, I clear the TileMap and the Area2D triggers, and render the new room as above. Then my character goes about his merry way.
However, a non-trivial percentage of the time, the character seems to immediately set off one of the newly-spawned door triggers in the new room.
I do the following when a new room is supposed to be rendered:
- Clear the TileMap and destroy/free the old triggers.
- Set the location of the character to be someplace off-screen.
- Create the TileMap.
- Create the door triggers and wire them to the "body_entered" signal.
- Set the location of the character to be someplace not near any door triggers.
And yet, I've confirmed that, despite the above, the character sometimes immediately overlaps one of the door triggers, and I can't figure out why. Best guess is that the location data of the character is stale when the new door triggers are spawned, possibly as part of a race condition. I've even tried changing the collision bitmask/layer of the character to before and after creating the door triggers, but, it doesn't correct the the situation.
I've tried examining the location of the colliding body (i.e. the KinematicCharacter2D), and while I've verified it is, in fact, the character, I'm guessing that because the "body" argument of the "body_entered" signal is passed by reference, that by the time I examine the location of the character, it's at the appropriate location (and nowhere near any of the triggers).
Am I going about this the wrong way? Or does any of this sound like something a Godot noob would do?
Thanks in advance.