godotengine / godot

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

CollisionShape2D with top_level has inconsistent position for physics #98741

Open tGautot opened 2 hours ago

tGautot commented 2 hours ago

Tested versions

System information

Godot v4.4.dev3 - Windows 10 - Vulkan (Forward+) - NVIDIA 3060 Ti

Issue description

When dynamically adding a collision shape with top_level set and then placing it through its global_position, the effective position (used in the physics server) seems to differ, thus giving incorrect collisions.

Steps to reproduce

There are 2 scenes, in the project, for each. In the first one, there are 2 areas overlapping through 2 circle collision shapes. In the second scene one of the areas is left untuched, but the other one is created and placed dynamically at the exam same position as it was in the first node. Important: Note that it is added as a child of an "strangely" offset node.

You can run both scenes with "Visible Collision Shapes", in both case you should see the shapes overlap. When the scenes are running you can left click to see the overlapping areas in the output console, in the first scene you should see something, while the second one should return an empty array.

Minimal reproduction project (MRP)

mrp-toplevelcollisionshape2d.zip

tGautot commented 2 hours ago

This is linked to #95641 (probably same underlying issue but lower scope) and #66710 (probably same issue but in 3D)