godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.11k stars 20.2k forks source link

Body_Exited Signal incorrectly triggering between CollisionPolygon2D Segments despite build mode being "Solids" #86640

Open laurenmedved opened 8 months ago

laurenmedved commented 8 months ago

Tested versions

v4.1.stable.official [970459615]

System information

Godot v4.1.stable - macOS 13.5.2 - Vulkan (Forward+) - integrated Intel(R) Iris(TM) Plus Graphics 655 - Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz (8 Threads)

Issue description

Player is detected as leaving the area when they are still within the same CollisonPolygon2D. The exited signal for this only triggers when the player 'undos' within the top portion of this puzzle, which happens to be the only area where the polygon shape segments are pure rectangles. The player can undo in other sections of the puzzle without the exited signal triggering.

The exited signal should only trigger if the player is stepping outside of the entire collision area.

Steps to reproduce

Walk the player around using WASD or arrow keys. You have a move count and will need to recharge by stepping on the lightning bolt tiles. At anytime, you can undo by pressing "Q". In the first part of the puzzle, everything should work as intended, however once you get to the last stretch (as shown in this screenshot & video) undoing your player will cause the puzzle to deactivate because the body_exited signal is triggered. This only happens if the player is undone between the colored segments in this section.

https://github.com/godotengine/godot/assets/60891368/211625a3-9cf4-46d7-9633-8b0980833cdc

Screenshot 2023-12-30 at 11 15 13 AM

Currently I am able to work around this by setting up a function to check when the player is being 'undone' and then checking when that is false within the body_exited signal before executing any other code. This should be fine for my project but it still doesn't solve the fact that the exited signal is being triggered here in general.

Minimal reproduction project (MRP)

ISSUE_12302023.zip

Rindbee commented 8 months ago

The logic to check whether to exit the old shape is placed before the logic to check to enter the new shape.

Check whether to exit the old shape.

https://github.com/godotengine/godot/blob/13a0d6e9b253654f5cc2a44f3d0b3cae10440443/servers/physics_2d/godot_step_2d.cpp#L157

Check whether to enter the new shape.

https://github.com/godotengine/godot/blob/13a0d6e9b253654f5cc2a44f3d0b3cae10440443/servers/physics_2d/godot_step_2d.cpp#L255-L257

Exiting the last shape causes the body to exit.

MRP.zip