Infohazard.HyperNav 1.1.5
3D Navigation for Flying Characters
Loading...
Searching...
No Matches
Infohazard.HyperNav.NavAgent Class Reference

A script that can be used to calculate paths by any entity that needs to use HyperNav for navigation. More...

Classes

class  PropNames
 This is used to refer to the names of private fields in this class from a custom Editor. More...
 

Public Member Functions

virtual void Stop (bool abortPaths)
 Stop following the current path, and optionally cancel all path requests. More...
 
virtual void UpdatePath ()
 Request a new path from the current position to the desired destination. More...
 

Protected Member Functions

virtual void Awake ()
 Sets the AvoidanceAgent.Infohazard.HyperNav.AvoidanceAgent.InputVelocityFunc. More...
 
virtual void OnEnable ()
 Resets MeasuredVelocity and sets Arrived to true. More...
 
virtual void OnDisable ()
 Stops all pathfinding and cancels path requests. More...
 
virtual void Update ()
 Updates measured velocity and current index in path. More...
 
virtual void OnDrawGizmos ()
 Draws the current path as a sequence of debug lines if DebugPath is true. More...
 
virtual Vector3 CalculateDesiredNavigationVelocity ()
 Calculate the velocity the agent wants to move in, in the range [0, 1]. More...
 
virtual void UpdateMeasuredVelocity ()
 Update the value of MeasuredVelocity, which is used to determine StoppingDistance. More...
 
virtual void UpdatePathIndex ()
 Update the current path index, which is used to determine NextWaypoint. More...
 
virtual void OnPathReady (long id, NavPath path)
 Callback that is received when a pathfinding request completes, which should start moving along that path. More...
 

Properties

float Acceptance [get, set]
 How close the agent must get to a destination before it is considered to have arrived. More...
 
float AccelerationEstimate [get, set]
 (Serialized) This should be set to the maximum acceleration of your agent. More...
 
float SampleRadius [get, set]
 The radius to search when finding the nearest NavVolume. More...
 
float DesiredSpeedRatio [get, set]
 The desired fraction of the maximum speed to travel at. More...
 
bool DebugPath [get, set]
 Whether to draw a debug line in the scene view showing the agent's current path. More...
 
bool KeepPathWhileCalculating [get, set]
 Whether to keep following the current path while waiting for a new path to finish calculating. More...
 
AvoidanceAgent AvoidanceAgent [get, set]
 AvoidanceAgent that this agent uses for avoidance (can be null). More...
 
bool ControlAvoidanceIsActive [get, set]
 If true, the Infohazard.HyperNav.AvoidanceAgent.IsActive state of the AvoidanceAgent is set based on whether there is a current valid path. More...
 
bool IsPathPending [get]
 Whether a path is currently in the process of being calculated for this agent. More...
 
virtual float StoppingDistance [get]
 The distance that it will take the agent to come to a stop from its current velocity, determined using the AccelerationEstimate. More...
 
Vector3 NextWaypoint [get]
 The current path waypoint that the agent is trying to move towards. More...
 
bool Arrived [get, private set]
 True if the agent has no active or pending path. More...
 
Vector3 Destination [get, set]
 Get or set the agent's destination (the position it is trying to get to). More...
 
Vector3 MeasuredVelocity [get, protected set]
 Velocity of the agent measured as delta position / delta time over the last frame, which is used to determine stopping distance. More...
 
NavPath CurrentPath [get, set]
 The current path that the agent is following. More...
 
float AvoidanceMaxSpeed [get, set]
 Maximum speed possible by this agent when avoiding obstacles. More...
 

Events

Action PathReady
 Invoked when the agent finds a path to the destination. More...
 
Action PathFailed
 Invoked when the agent fails to find a path to the destination. More...
 

Private Attributes

float _acceptance = 1
 (Serialized) How close the agent must get to a destination before it is considered to have arrived. More...
 
float _accelerationEstimate = 0
 (Serialized) This should be set to the maximum acceleration of your agent (can be set dynamically as well). More...
 
float _sampleRadius = 2
 (Serialized) The radius to search when finding the nearest NavVolume. More...
 
float _desiredSpeedRatio = 1
 (Serialized) The desired fraction of the maximum speed to travel at. More...
 
bool _debugPath = true
 (Serialized) Whether to draw a debug line in the scene view showing the agent's current path. More...
 
bool _keepPathWhileCalculating = true
 (Serialized) Whether to keep following the current path while waiting for a new path to finish calculating. More...
 
AvoidanceAgent _avoidanceAgent
 (Serialized) AvoidanceAgent that this agent uses for avoidance (can be null). More...
 
bool _controlAvoidanceIsActive = true
 (Serialized) If true, the Infohazard.HyperNav.AvoidanceAgent.IsActive state of the AvoidanceAgent is set based on whether there is a current valid path. More...
 

Detailed Description

A script that can be used to calculate paths by any entity that needs to use HyperNav for navigation.

While a NavAgent is not necessary to use HyperNav, it makes pathfinding easier. The NavAgent does not impose any restrictions on how movement occurs, nor does it actually perform any movement. It simply provides a desired movement velocity, which other scripts on the object are responsible for using however they need.

The agent can have one active path (the path it is currently following), but can have multiple pending paths (paths in the process of being calculated by a NavPathfinder).

If you desire smoother movement then what the NavAgent provides, see SplineNavAgent.

Member Function Documentation

◆ Awake()

virtual void Infohazard.HyperNav.NavAgent.Awake ( )
protectedvirtual

◆ CalculateDesiredNavigationVelocity()

virtual Vector3 Infohazard.HyperNav.NavAgent.CalculateDesiredNavigationVelocity ( )
protectedvirtual

Calculate the velocity the agent wants to move in, in the range [0, 1].

Reimplemented in Infohazard.HyperNav.SplineNavAgent.

◆ OnDisable()

virtual void Infohazard.HyperNav.NavAgent.OnDisable ( )
protectedvirtual

Stops all pathfinding and cancels path requests.

Reimplemented in Infohazard.HyperNav.SplineNavAgent.

◆ OnDrawGizmos()

virtual void Infohazard.HyperNav.NavAgent.OnDrawGizmos ( )
protectedvirtual

Draws the current path as a sequence of debug lines if DebugPath is true.

Reimplemented in Infohazard.HyperNav.SplineNavAgent.

◆ OnEnable()

virtual void Infohazard.HyperNav.NavAgent.OnEnable ( )
protectedvirtual

Resets MeasuredVelocity and sets Arrived to true.

◆ OnPathReady()

virtual void Infohazard.HyperNav.NavAgent.OnPathReady ( long  id,
NavPath  path 
)
protectedvirtual

Callback that is received when a pathfinding request completes, which should start moving along that path.

Parameters
idThe id of the path request.
pathThe completed path, which is null if no path was found.

Reimplemented in Infohazard.HyperNav.SplineNavAgent.

◆ Stop()

virtual void Infohazard.HyperNav.NavAgent.Stop ( bool  abortPaths)
virtual

Stop following the current path, and optionally cancel all path requests.

Parameters
abortPathsWhether to cancel pending path requests.

Reimplemented in Infohazard.HyperNav.SplineNavAgent.

◆ Update()

virtual void Infohazard.HyperNav.NavAgent.Update ( )
protectedvirtual

Updates measured velocity and current index in path.

Reimplemented in Infohazard.HyperNav.SplineNavAgent.

◆ UpdateMeasuredVelocity()

virtual void Infohazard.HyperNav.NavAgent.UpdateMeasuredVelocity ( )
protectedvirtual

Update the value of MeasuredVelocity, which is used to determine StoppingDistance.

◆ UpdatePath()

virtual void Infohazard.HyperNav.NavAgent.UpdatePath ( )
virtual

Request a new path from the current position to the desired destination.

It is usually not necessary to call this yourself, as it is called when setting Destination. However, if the agent gets stuck or pushed off course, you may wish to use this to get a new path.

◆ UpdatePathIndex()

virtual void Infohazard.HyperNav.NavAgent.UpdatePathIndex ( )
protectedvirtual

Update the current path index, which is used to determine NextWaypoint.

Member Data Documentation

◆ _accelerationEstimate

float Infohazard.HyperNav.NavAgent._accelerationEstimate = 0
private

(Serialized) This should be set to the maximum acceleration of your agent (can be set dynamically as well).

◆ _acceptance

float Infohazard.HyperNav.NavAgent._acceptance = 1
private

(Serialized) How close the agent must get to a destination before it is considered to have arrived.

◆ _avoidanceAgent

AvoidanceAgent Infohazard.HyperNav.NavAgent._avoidanceAgent
private

(Serialized) AvoidanceAgent that this agent uses for avoidance (can be null).

◆ _controlAvoidanceIsActive

bool Infohazard.HyperNav.NavAgent._controlAvoidanceIsActive = true
private

(Serialized) If true, the Infohazard.HyperNav.AvoidanceAgent.IsActive state of the AvoidanceAgent is set based on whether there is a current valid path.

◆ _debugPath

bool Infohazard.HyperNav.NavAgent._debugPath = true
private

(Serialized) Whether to draw a debug line in the scene view showing the agent's current path.

◆ _desiredSpeedRatio

float Infohazard.HyperNav.NavAgent._desiredSpeedRatio = 1
private

(Serialized) The desired fraction of the maximum speed to travel at.

◆ _keepPathWhileCalculating

bool Infohazard.HyperNav.NavAgent._keepPathWhileCalculating = true
private

(Serialized) Whether to keep following the current path while waiting for a new path to finish calculating.

◆ _sampleRadius

float Infohazard.HyperNav.NavAgent._sampleRadius = 2
private

(Serialized) The radius to search when finding the nearest NavVolume.

Property Documentation

◆ AccelerationEstimate

float Infohazard.HyperNav.NavAgent.AccelerationEstimate
getset

(Serialized) This should be set to the maximum acceleration of your agent.

This is used to determine when the agent needs to start slowing down when approaching its destination.

◆ Acceptance

float Infohazard.HyperNav.NavAgent.Acceptance
getset

How close the agent must get to a destination before it is considered to have arrived.

Note that setting acceptance too low may prevent the agent from ever stopping, but setting it to high can make the agent stop too far from the destination.

◆ Arrived

bool Infohazard.HyperNav.NavAgent.Arrived
getprivate set

True if the agent has no active or pending path.

◆ AvoidanceAgent

AvoidanceAgent Infohazard.HyperNav.NavAgent.AvoidanceAgent
getset

AvoidanceAgent that this agent uses for avoidance (can be null).

◆ AvoidanceMaxSpeed

float Infohazard.HyperNav.NavAgent.AvoidanceMaxSpeed
getset

Maximum speed possible by this agent when avoiding obstacles.

◆ ControlAvoidanceIsActive

bool Infohazard.HyperNav.NavAgent.ControlAvoidanceIsActive
getset

If true, the Infohazard.HyperNav.AvoidanceAgent.IsActive state of the AvoidanceAgent is set based on whether there is a current valid path.

◆ CurrentPath

NavPath Infohazard.HyperNav.NavAgent.CurrentPath
getset

The current path that the agent is following.

◆ DebugPath

bool Infohazard.HyperNav.NavAgent.DebugPath
getset

Whether to draw a debug line in the scene view showing the agent's current path.

◆ DesiredSpeedRatio

float Infohazard.HyperNav.NavAgent.DesiredSpeedRatio
getset

The desired fraction of the maximum speed to travel at.

◆ Destination

Vector3 Infohazard.HyperNav.NavAgent.Destination
getset

Get or set the agent's destination (the position it is trying to get to).

If set within the _acceptance radius of the current position, will abort all movement.

◆ IsPathPending

bool Infohazard.HyperNav.NavAgent.IsPathPending
get

Whether a path is currently in the process of being calculated for this agent.

◆ KeepPathWhileCalculating

bool Infohazard.HyperNav.NavAgent.KeepPathWhileCalculating
getset

Whether to keep following the current path while waiting for a new path to finish calculating.

If true, there can be two pending paths at the same time - the most and least recently requested ones. This ensures that even when the agent is receiving pathfinding requests faster than they can be calculated, they will still finish and the agent will not be deadlocked and unable to ever complete a path.

◆ MeasuredVelocity

Vector3 Infohazard.HyperNav.NavAgent.MeasuredVelocity
getprotected set

Velocity of the agent measured as delta position / delta time over the last frame, which is used to determine stopping distance.

This value is calculated in UpdateMeasuredVelocity. You can override that method to implement your own logic for calculating velocity.

◆ NextWaypoint

Vector3 Infohazard.HyperNav.NavAgent.NextWaypoint
get

The current path waypoint that the agent is trying to move towards.

If there is no active path, will return the agent's current position.

◆ SampleRadius

float Infohazard.HyperNav.NavAgent.SampleRadius
getset

The radius to search when finding the nearest NavVolume.

◆ StoppingDistance

virtual float Infohazard.HyperNav.NavAgent.StoppingDistance
get

The distance that it will take the agent to come to a stop from its current velocity, determined using the AccelerationEstimate.

Event Documentation

◆ PathFailed

Action Infohazard.HyperNav.NavAgent.PathFailed

Invoked when the agent fails to find a path to the destination.

◆ PathReady

Action Infohazard.HyperNav.NavAgent.PathReady

Invoked when the agent finds a path to the destination.


The documentation for this class was generated from the following file: