Agent Extensions
Has Reached Destination
This checks if the NavMeshAgent has reached its destination.
NavMeshAgent agent = GetComponent<NavMeshAgent>();
if (agent.HasReachedDestination())
{
Debug.Log("The agent has reached its destination.");
}Avoid Obstacles
This adjusts the stopping distance based on obstacle detection.
NavMeshAgent agent = GetComponent<NavMeshAgent>();
LayerMask obstacleLayer = LayerMask.GetMask("Obstacle");
agent.AvoidObstacles(rayDistance: 2f, layerMask: obstacleLayer, stoppingDistance: 1f);Can See Target
This checks if the agent can see a target based on raycasting and field of view.
NavMeshAgent agent = GetComponent<NavMeshAgent>();
Transform target = GameObject.Find("Target").transform;
if (agent.CanSeeTarget(target, rayDistance: 10f, fieldOfView: 60f))
{
Debug.Log("The agent can see the target.");
} else {
Debug.Log("The agent cannot see the target.");
}Can Detect Target
This checks if the agent can detect the target within a specified range.
Seek
This moves the agent toward a target position by calculating a steering force based on a maximum speed.
Avoid
This calculates the steering force to avoid obstacles around the agent.
Get Flocking Steering
This calculates the steering force for flocking behavior based on neighboring agents' positions and velocities.
Last updated