-
Notifications
You must be signed in to change notification settings - Fork 3
NavMeshAgent.raycast
Wyatt Gillette edited this page Oct 28, 2021
·
1 revision
public boolean raycast(Vector3f targetPosition, NavMeshHit hit);
targetPosition | The desired end position of movement. |
hit | Properties of the obstacle detected by the ray (if any). |
boolean True if there is an obstacle between the agent and the target position, otherwise false.
Trace a straight path towards a target position in the NavMesh without moving the agent.
This function follows the path of a "ray" between the agent's position and the specified target position. If an obstruction is encountered along the line then a true value is returned and the position and other details of the obstructing object are stored in the hit parameter. This can be used to check if there is a clear shot or line of sight between a character and a target object.
Vector3f targetPos;
NavMeshAgent agent;
NavMeshHit hit = new NavMeshHit();
if (!agent.raycast(targetPos, hit)) {
// Target is "visible" from our position.
}