godot icon indicating copy to clipboard operation
godot copied to clipboard

Area3D has_overlapping_bodies() failing for some objects

Open blackears opened this issue 9 months ago • 2 comments

Tested versions

v4.3.stable.official [77dcf97d8]

System information

Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated AMD FirePro W2100 (Advanced Micro Devices, Inc.; 27.20.21026.2006) - Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz (4 Threads)

Issue description

I'm trying to create a detector that can tell when my player character is close to certain static objects. Sometimes it works, and sometimes it ignores objects the Area3D is plainly intersecting with. I've tried this with both regular Godot physics and Jolt.

Steps to reproduce

Run the attached project. The project has two scenes: area_detect_works.tscn and doesnt_work.tscn. Both are the same except the Area3D has been slightly offset in the first scene. In the first scene the has_overlapping_objects() correctly detects the intersection and in the second case it doesn't.

Minimal reproduction project (MRP)

getcollidingbodiesfail.zip

blackears avatar Feb 22 '25 11:02 blackears

Could you test if is reproducible in Godot 4.4 rc 1?

matheusmdx avatar Feb 22 '25 19:02 matheusmdx

I just tried Godot 4.4 rc 1 and it's happening there too.

blackears avatar Feb 22 '25 19:02 blackears

ver. 4.4.1 Area3D.has_overlapping_bodies() doesn't detect StaticBody3D. Even though StaticBody3D inherits PhysicsBody3D and Area3D.has_overlapping_bodies() must detect any PhysicsBody3D, as stated in it's Doc paragraph (no issues with Rigidbody3D). The workaround is to add Area3D to a StaticBody3D and use Area3D.has_overlapping_areas(), which works just fine. IMHO at least mention of that "feature" must be added, if fix is too complicated.

repunchpunch avatar Apr 05 '25 17:04 repunchpunch

After some more research, it seems that for Jolt, you need to specifically enable this in the project properties. You need to click on Advance Settings, then Physics > Jolt Physics 3D > Areas Detect Static Bodies. This is disabled by default to prevent Area3Ds from consuming CPU cycles. I think the idea is to make these checks with ray casts where possible.

blackears avatar Apr 15 '25 14:04 blackears