bool
Linecast
(
)
True if there is an obstacle between start and end on the navmesh.
This is a simple api to check if there is an obstacle between two points. If you need more detailed information, you can use GridGraph.Linecast or NavmeshBase.Linecast (for navmesh/recast graphs). Those overloads can also return which nodes the line passed through, and allow you use custom node filtering.
var start = transform.position;
var end = start + Vector3.forward * 10;
if (AstarPath.active.Linecast(start, end, out var hit)) {
Debug.DrawLine(start, end, Color.red);
Debug.DrawRay(hit.point, Vector3.up, Color.red);
} else {
Debug.DrawLine(start, end, Color.green);
}
NoteOnly grid, recast and navmesh graphs support linecasts. The closest raycastable graph to the start point will be used for the linecast.
Linecasts cannot pass through off-mesh links.