Godot's .intersect_ray() detection appears to be buggy on Terrain3D, differs from Terrain3D's get_height() in some rectangles:
Here's a scan of vertical rays shot down all over the terrain via node.get_world_3d().direct_space_state.intersect_ray:
As you can see, two weird rectangles don't seem to be detected correctly, I added some line to show where:
Here is the detection code we use to place these cubes:
var origin = Vector3(posx, 999999, posz)
var target = Vector3(posx, -999999, posz)
var height
if not use_physics_ray:
# (code path not entered)
else:
var query = PhysicsRayQueryParameters3D.create(
origin, target)
query.set_collision_mask(1)
query.collide_with_areas = true
query.collide_with_bodies = true
query.hit_back_faces = true
query.hit_from_inside = true
var collision = space_state.intersect_ray(query)
height = min_y
if collision:
height = collision.position.y
_height_field[i + k * slices_x] = height
The collision mesh visualization indicates that the Terrain3D mesh is correct and this is a bug with Godot's physics code:
My apologies if this is some obvious issue on our side, but we looked at this with two people and couldn't quite figure out a reasonable cause for this. And sorry that we didn't test the demo, our code wasn't that quick to transfer over.
We've for now moved on to use a different function for this, and haven't gotten around to an MRP yet. So I'll close this for now, and reopen if we ever should run into this again in a nicely reproducible case.
Tested versions
Godot v4.2.2.stable from Flathub
System information
Godot v4.2.2.stable - Freedesktop SDK 23.08 (Flatpak runtime) - Wayland - Vulkan (Forward+) - integrated AMD Custom GPU 0405 (RADV VANGOGH) () - AMD Custom APU 0405 (8 Threads)
Issue description
Godot's .intersect_ray() detection appears to be buggy on Terrain3D, differs from Terrain3D's get_height() in some rectangles:
Here's a scan of vertical rays shot down all over the terrain via
node.get_world_3d().direct_space_state.intersect_ray
:As you can see, two weird rectangles don't seem to be detected correctly, I added some line to show where:
Here is the detection code we use to place these cubes:
The collision mesh visualization indicates that the Terrain3D mesh is correct and this is a bug with Godot's physics code:
My apologies if this is some obvious issue on our side, but we looked at this with two people and couldn't quite figure out a reasonable cause for this. And sorry that we didn't test the demo, our code wasn't that quick to transfer over.
Steps to reproduce
Minimal reproduction project (MRP)
I currently don't have one ready :cry: