RayCast3D ignoring StaticBody3D generated with create_trimesh_collision()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ithiro

I’m making a procedurally generated 3D world using chunks that generate collisions through MeshInstance3D.create_trimesh_collision(), and they’re working as expected. Below are screenshots that show the current setup of the generated chunks, the Raycast3D, etc.

The chunk generation, and the RayCast3D config

However, when I try to use a RayCast3D to get the terrain’s current Y coordinate, it doesn’t seem to detect it, despite apparently being on the correct collision layers and masks. The below screenshot has the player below ground, and the raycast pointing up, and it should have detected the terrain above, but doesn’t.

In game, RayCast3D isn't detecting the terrain above

I set it up to print whatever it detects a collision with, and it even detects other objects, everything but the terrain itself. Please help, and thank you in advance!

:bust_in_silhouette: Reply From: mrmelonmonkey

I had a very similar problem. It seems to be solved by enabling “collision with areas” on the Raycast3D.
I am not sure though if the StaticBody3D is intended to be counted as area or if it’s a bug. Maybe its because it’s not a closed object but a plane that has no inside.
Hope this helps.

Thanks for your answer, and your ideas could actually help someone with a similar problem.

But I did manage to solve this issue on my own, and the thing was that the RayCast must not only be set to detect collisions from inside, but also the “side” of the terrain plane matters for collisions, as if it’s the “wrong” side (sorta like the side the plane doesn’t draw) the RayCast won’t detect it. Setting one or both of these parameters to adequate values should solve the issue.

Basically either make your RayCast detect collisions from inside areas, or make the area report collisions from both sides, or both.

ithiro | 2023-03-23 13:07