godotengine / godot

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

Godot's .intersect_ray() detection appears to be buggy on Terrain3D, differs from Terrain3D's get_height() in some rectangles #95458

Closed ell1e closed 1 week ago

ell1e commented 1 month ago

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:

Screenshot_20240811_203258

As you can see, two weird rectangles don't seem to be detected correctly, I added some line to show where:

Screenshot_20240811_203258_2

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:

Screenshot_20240813_031906

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

  1. Set up a terrain with Terrain3D
  2. Scan it with vertical rays all over the terrain

Minimal reproduction project (MRP)

I currently don't have one ready :cry:

ell1e commented 1 week ago

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.