NavMeshAgentΒΆ
Inherited: NativeBehaviour
DescriptionΒΆ
A navigation agent finds a path on the navigation mesh and advances its owner along the resulting waypoints. The agent can be controlled by setting a target point with moveTo() or by following another actor with moveToActor().
The agent uses the configured agentType() to select a compatible navigation mesh. Its movement is limited by speed(), acceleration(), and angularSpeed(). When autoBraking() is enabled, the agent slows down near the end of the path. When autoRepath() is enabled, it recalculates the path after detecting a deviation or a stalled movement.
Public MethodsΒΆ
float |
acceleration () const |
int |
agentType () const |
float |
angularSpeed () const |
bool |
autoBraking () const |
bool |
autoRepath () const |
Vector3Vector |
calculatePath (const Vector3 & target) |
void |
|
bool |
moveTo (const Vector3 & target) |
bool |
moveToActor (Actor * targetActor) |
const Vector3Vector |
path () const |
void |
pathFailed () |
void |
pathFound () |
void |
pause (bool paused) |
void |
setAcceleration (float acceleration) |
void |
setAgentType (int type) |
void |
setAngularSpeed (float angularSpeed) |
void |
setAutoBraking (bool autoBraking) |
void |
setAutoRepath (bool autoRepath) |
void |
setSpeed (float speed) |
void |
setStoppingDistance (float stoppingDistance) |
float |
speed () const |
state () const |
|
void |
stop () |
float |
stoppingDistance () const |
void |
stuck () |
const Vector3 & |
target () const |
void |
unstuck () |
velocity () const |
|
void |
Public EnumsΒΆ
enum NavMeshAgent::NavigationState
Describes the current navigation state of the agent.
Constant |
Value |
Description |
NavMeshAgent::Idle |
0 |
The agent has no active navigation request. |
NavMeshAgent::Moving |
1 |
The agent is following the current path. |
NavMeshAgent::Pathfinding |
2 |
The agent is calculating a path to its target. |
NavMeshAgent::Stuck |
3 |
The agent has not moved for the configured stuck threshold. |
NavMeshAgent::Arrived |
4 |
The agent has reached its destination. |
Static MethodsΒΆ
None
Methods DescriptionΒΆ
NavMeshAgent::~NavMeshAgent ()
Destroys the navigation agent and stops its active navigation request.
float NavMeshAgent::acceleration () const
Returns the maximum movement acceleration in world units per second squared.
See also setAcceleration().
int NavMeshAgent::agentType () const
Returns the navigation mesh agent type used for pathfinding.
The value selects the agent configuration registered in NavigationSystem.
See also setAgentType().
float NavMeshAgent::angularSpeed () const
Returns the maximum rotation speed in degrees per second.
See also setAngularSpeed().
bool NavMeshAgent::autoBraking () const
Returns true when the agent automatically slows down near the end of its path.
See also setAutoBraking().
bool NavMeshAgent::autoRepath () const
Returns true when the agent automatically recalculates a deviated or stalled path.
See also setAutoRepath().
Vector3Vector NavMeshAgent::calculatePath (Vector3 & target)
Calculates a path from the agentβs current position to the target point.
Returns an empty vector when no path can be found.
See also moveTo().
void NavMeshAgent::destinationReached ()
Emitted when the agent reaches its destination.
bool NavMeshAgent::moveTo (Vector3 & target)
Starts moving the agent to the target point.
The request replaces the current path and emits pathFound() when a path is available, or pathFailed() when pathfinding fails.
Returns true after the navigation request has been submitted.
See also stop() and moveToActor().
bool NavMeshAgent::moveToActor (Actor * targetActor)
Starts moving the agent to the position of targetActor.
Returns false when targetActor or its transform is null. Otherwise, returns the result of moveTo().
See also moveTo().
const Vector3Vector NavMeshAgent::path () const
Returns the current path as a sequence of waypoints.
void NavMeshAgent::pathFailed ()
Emitted when pathfinding cannot produce a path to the requested target.
void NavMeshAgent::pathFound ()
Emitted when a path to the requested target has been found.
void NavMeshAgent::pause (bool paused)
Pauses or resumes movement according to the paused value.
While paused, the current path and navigation state are preserved.
void NavMeshAgent::setAcceleration (float acceleration)
Sets the maximum movement acceleration in world units per second squared.
The acceleration value limits how quickly the movement speed can change.
See also acceleration().
void NavMeshAgent::setAgentType (int type)
Sets the navigation mesh agent type used for pathfinding.
The type value is an index of an agent configuration registered in NavigationSystem.
See also agentType().
void NavMeshAgent::setAngularSpeed (float angularSpeed)
Sets the maximum rotation speed in degrees per second.
The angularSpeed value limits rotation in degrees per second.
See also angularSpeed().
void NavMeshAgent::setAutoBraking (bool autoBraking)
Enables or disables automatic braking near the end of the path.
When autoBraking is true, the agent slows down near the end of the path.
See also autoBraking().
void NavMeshAgent::setAutoRepath (bool autoRepath)
Enables or disables automatic path recalculation.
When autoRepath is true, the agent recalculates a deviated or stalled path.
See also autoRepath().
void NavMeshAgent::setSpeed (float speed)
Sets the maximum movement speed in world units per second.
The speed value limits movement to world units per second.
See also speed().
void NavMeshAgent::setStoppingDistance (float stoppingDistance)
Sets the distance at which the agent considers a waypoint reached.
The stoppingDistance value specifies the waypoint reach distance in world units.
See also stoppingDistance().
float NavMeshAgent::speed () const
Returns the maximum movement speed in world units per second.
See also setSpeed().
NavMeshAgent::NavigationState NavMeshAgent::state () const
Returns the current navigation state.
void NavMeshAgent::stop ()
Stops navigation, clears the current path, and resets the agent velocity.
float NavMeshAgent::stoppingDistance () const
Returns the distance at which the agent considers a waypoint reached.
See also setStoppingDistance().
void NavMeshAgent::stuck ()
Emitted when the agent is detected as stuck.
const Vector3 & NavMeshAgent::target () const
Returns the current navigation target.
void NavMeshAgent::unstuck ()
Emitted when a stuck agent starts moving again.
Vector3 NavMeshAgent::velocity () const
Returns the current movement velocity.
void NavMeshAgent::waypointReached ()
Emitted when the agent reaches a waypoint on its current path.