Skip to content

[GodotPhysics] Raycasts don't reliably collide with HeightMapShape3D #68238

Closed
@celeste-sinead

Description

@celeste-sinead

Godot version

v4.0.beta.custom_build.01ae26d31

System information

Pop!_OS 22.04, 5.19.0-76051900-generic, Intel(R) UHD Graphics (CML GT2)

Issue description

When casting rays from the camera in the direction of the mouse position, I found that in some camera positions and orientations, the result of the result of PhysicsDirectSpaceState3D.intersect_ray is empty where it ought to have found a collision.

When this occurs, there is generally a contiguous region of the heightmap through which rays cast from a given camera position won't produce a result. Different camera transforms produce different non-colliding regions (and some camera transforms result in no such regions). When I originally encountered this issue with non-flat heightmaps, I found non-colliding regions could occur anywhere in the heightmap, not necessarily touching edges, in non-rectangular shapes, and often multiple such regions would exist.

In the simplified reproduction project I've only observed rectangular non-colliding regions, usually at the +X edge but sometimes at +Z.

Steps to reproduce

I haven't isolated exact conditions for when this occurs. I've observed it to be sensitive to the following:

  • heightmap size: I've only been able to reproduce this with heightmaps of 20x20 and larger
  • raycast length: I've only been able to reproduce this with rays >20 length
  • camera transform (ray origin / direction): changes which regions of the heightmap don't collide, and in some cases prevent the issue. Directions closer to -Y seem much less likely to reproduce the issue.
  • heightmap shape: the flat heightmap in the repro project only seems to produce rectangular non-colliding regions at the edge of the heightmap, but for non-flat (specifically, simplex noise) maps I've seen multiple not-necessarily rectangular regions not necessarily touching edges.

The reproduction project sets a camera transform where the issue is apparent (and will cast rays to mouse position and position a sphere at the intersect location when detected). It also includes a script that casts an example ray that ought to collide but doesn't, and also draws a line corresponding to that ray to demonstrate visually that it ought to have collided.

Minimal reproduction project

heightmap_raycast_repro.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions