Open
Description
Tested versions
- Reproducible in Godot Engine v4.4.1 mono
System information
MacOS 15.5
Issue description
When using Raycast.GetCollisionFaceIndex
in conjunction with the MeshDataTool's meshDataTool.GetFaceVertex
, the resulting points are sometimes from a different face.
In some cases it works fine (as in 1 and 3), could this be to do with the way Godot creates concave collision meshes internally? I'm not sure where the problem is coming from but there seems to be some difference between the face index from the raycast and the face index from the meshdatatool.
Steps to reproduce
Here is the basic script I've been using in my tests, I've also included a simplified project demonstrating the issue.
public override void _PhysicsProcess(double delta)
{
base._PhysicsProcess(delta);
// Move raycast point
float time = Time.GetTicksMsec();
float offset = Mathf.Sin((time) / (1000) );
raycast.Position = new Vector3(offset * 4, raycast.Position.Y, 0);
// Update collision data
if (raycast.IsColliding())
{
CollisionObject3D other = (CollisionObject3D)raycast.GetCollider();
meshInstance3D = other.GetParent().GetNode<MeshInstance3D>("Mesh");
meshDataTool.CreateFromSurface((ArrayMesh)meshInstance3D.Mesh, 0);
// Highlight points that make up the collision face
int collisionFaceIndex = raycast.GetCollisionFaceIndex();
for (var i = 0; i < 3; i++)
{
var index = meshDataTool.GetFaceVertex(collisionFaceIndex, i);
var vertex = meshInstance3D.ToGlobal(meshDataTool.GetVertex(index));
debugSpheres[i].GlobalPosition = vertex;
}
}
}
Minimal reproduction project (MRP)
Metadata
Metadata
Assignees
Type
Projects
Status
For team assessment