godotengine / godot

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

[Godot 4.0 Alpha 14] Area3D collision bodies behaves differently between BoxShape3D and Trimesh #64588

Open Sch1nken opened 2 years ago

Sch1nken commented 2 years ago

Godot version

4.0 Alpha 14 Official

System information

Manjaro Linux, AMD Ryzen 4800H iGPU

Issue description

Texting an Area3D collision against a StaticBody3D+CollisionShape3D+BoxShape3d and a StaticBody3D+CollisionShape3D+Trimesh (From a Box with the same dimensions) has different collision detection results. Mainly the Trimesh collision seems "broken". The collision is only detected while >50% of the Area3D is "outside" of the Trimesh.

Video: https://user-images.githubusercontent.com/11414422/185504961-e183801c-b94e-4be1-90f4-2ece1f696a09.mp4

Controls for the demo: "ui_left" (Left Arrow): Move box to the left "ui_right" (Right Arrow): Move box to the right "ui_select" (Space): Align camera (due to perspective etc)

Steps to reproduce

Create a Trimesh Collision Sibling from a Mesh (here: from a glb).

Minimal reproduction project

collisiontest3d.zip

CristianoSimao commented 2 years ago

Yes. Trimesh have problems, see here: https://github.com/godotengine/godot/issues/64615

rburing commented 2 years ago

To detect collisions with the trimesh surface from both sides, you can enable the backface_collision property of the ConcavePolygonShape3D. This makes the Area3D work in the sense that it detects collisions with the surface.

It is true that the ConcavePolygonShape3D does not support detecting collisions with the "inside" of the shape, because in general the shape is just a collection of triangle faces, with no natural notion of what is the "inside". This is made clearer in the 2D editor, where the ConcavePolygonShape2D is visually just a collection of line segments, which is not filled in.

In contrast, convex shapes have a natural inside; ConvexPolygonShape2D and ConvexPolygonShape3D (and most other specialized shapes) do support detecting collisions with the inside.

This definitely needs to be documented, and perhaps a configuration warning should be added to Area2D and Area3D, since this behavior of concave shapes is more likely to be confusing than to have an actual use case.

CristianoSimao commented 2 years ago

Thank you for the explanation Ricardo. And thanks for the phrase " This definitely needs to be documented ". Various vital information and features are not documented or have some simple lines of description not showing the behavior of the functions in the API, and this makes it difficult for new users like me and many other people uses Godot. Some great information are in the Tutorial category and If you are searching some official description of the function in the API, Tutorial is not the first place to search... and the search bar inside the documentation not find good results, searching in Google is some times the only way to find information in the Godot documentation.