Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | MEDBVLL |
I have a Gridmap with a Cube mesh that looks like this:
Additionally, I have a separate static body, with a CSGBox and CollisionShape in the scene:
When I send a ray from the mouse position relative to the camera to the world space, I get the raycast hit information when I click on the static body, but whenever I click on my Cubes on the GridMap, I get nothing back.
This is the code I use to throw rays:
using Godot;
using System;
public class CameraController : Camera
{
private const float MOUSE_RAY_LENGTH = 100;
private Godot.Collections.Array _rayExclusions;
public override void _Ready()
{
_rayExclusions = new Godot.Collections.Array(this);
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton eventMouseButton && eventMouseButton.Pressed && eventMouseButton.ButtonIndex == 1)
{
Vector3 from = this.ProjectRayOrigin(eventMouseButton.Position);
Vector3 to = from + this.ProjectRayNormal(eventMouseButton.Position) * MOUSE_RAY_LENGTH;
GD.Print(GetWorld().DirectSpaceState.IntersectRay(from, to, _rayExclusions));
}
}
}
How do I properly detect Gridmap raycast collisions?