Plane.RayCast not hitting at all
Hi all,
I'm trying to find the intersection between a plane and a Ray in C#, based on the "onScreen" mouse position, but Panel.Raycast never hits. ¿any ideas?
private Plane aimPlane;
void Start()
{
aimPlane = new Plane(new Vector3(0, 0, 0), Vector3.forward.normalized);
}
private Vector3 InputPosToWorld()
{
Vector3 screenPos = Input.mousePosition;
// Cast a ray from screen point
Ray ray = mainCamera.ScreenPointToRay(screenPos);
float distance;
if (aimPlane.Raycast(ray, out distance))
{
Debug.Log("Distance: " + distance);
Vector3 hit = ray.GetPoint(distance);
Debug.DrawLine(ray.GetPoint(0), hit, new Color(1, 1, 1));
return hit;
}
else
{
Debug.DrawLine(ray.GetPoint(0), ray.GetPoint(50), new Color(1, 0, 0));
Debug.LogError("Can't reach clickable plane.");
return new Vector3(10, 10, 0);
}
}
I can see the debug Ray aiming at the plane, but it never hits.
Comment