godotengine / godot

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

Mesh Library "Apply MeshInstance Transforms" causes issues with raycasts on GridMap #75263

Open thesquaregroot opened 1 year ago

thesquaregroot commented 1 year ago

Godot version

4.0.1

System information

Windows 10, Vulkan, NVIDIA GeForce RTX 3060 Laptop GPU, Driver 528.24

Issue description

Ray casts on certain GridMap objects need to be much longer in order to hit the object. Recreating the issue seems to require:

  1. A semi-complicated mesh (I was able to recreate the issue with a hemisphere mesh but not a cube)
  2. The scale of the object to be set high (e.g. 100)
  3. The "Apply MeshInstance Transforms" option to be selected when the mesh library is exported

When ray casts do hit, they appear to report the correct position, but need to be extremely long (e.g. 100m) in order to actually hit the object. The colliders otherwise seems to work fine for physics purposes, so the issue seems isolated to ray casting.

In this photo, the 3 cylinders are showing the ray cast distance for a set of RayCast3D nodes. They should all be hitting the object, but only the green one is:

3-rays

Steps to reproduce

To create a mesh library with this issue, add a MeshInstance to a scene, set the mesh to something non-trivial (e.g. a sphere), and set the scale set to (100, 100, 100). Create a Trimesh Static Body on the mesh using the Mesh drop-down in the editor. Export the scene as a mesh library and make sure "Apply MeshInstanace Transforms" is checked. In a new scene, create a grid map with the exported mesh library and place one or more of the objects. Then perform any ray cast activity involving the grid map, either with the RayCast3D node or direct space state intersect_ray.

Minimal reproduction project

grid-map-raycasts.zip

RibalGZ commented 1 year ago

I also can reproduce this without the "Apply MeshInstance Transforms" option checked.