As mentioned above, you can use the Nav3DAgent script as a component for your game object and access it via GetComponent(), or you can create a subclass, which we personally find much more convenient.
The following public methods have been implemented to operate with Nav3DAgent.
- Applies the description for your agent.
public void SetDescription(Nav3DAgentDescription _Description)
- The order to move to the point. Any active order will be interrupted, the agent will start moving to the point, in accordance with the parameters of its description.
public void MoveTo(Vector3 _Point, Action _OnReach = null, Action<PathfindingError> _OnPathfindingFail = null)
- Add a destination to the queue. In this way, any number of sequence points can be added. If the agent executes the Follow Target order, then this order is interrupted and it starts following the point.
public void MoveToEnqueue(Vector3 _Point, Action _OnReach = null, Action<PathfindingError> _OnPathfindingFail = null)
- An order to chase a moving Transform.
public void FollowTarget( Transform _Target, float _OffsetToleranceUpdate, float _DistToReach = 0, Action _OnReach = null, Action _OnCancel = null, Action<PathfindingError> _OnPathfindingFail = null )
Transform _Target– Transform to target.
float _OffsetToleranceUpdate– the distance by which the shift of the target will cause the path to the target to be updated.
- If your agent has the Motion Navigation Type of the description set to GLOBAL, or GLOBAL_AND_LOCAL, then each time the pursued Transform is offset by more than _OffsetToleranceUpdate , it will cause the path to be recalculated.
float _DistToReach– the distance to the goal, when approaching which the goal will be considered reached. We would like to point out that in the case when an agent has to search for a global path, the goal may never be reached, because after reaching the end of the path, it may turn out that the goal has moved in the past time. Thus, the condition of the coincidence of the coordinates of the pursued target and the agent may be difficult to achieve.
Action _OnReach– delegate to be executed when the target is successfully reach
Action _OnCancel– a delegate executed if the reference to the pursued Transform becomes null or missing.
- Stops the execution of the previous commands.
public void Stop()
- Allows you to get a list of agents inside the radius _Radius from the agent. Using this method every time you run an update can negatively affect performance, so it is recommended not to call it too often (for example, several times per second should be enough for any game scenarios.).
public List<Nav3DAgent> GetAgentsInRadius(float _Radius, Predicate<Nav3DAgent> _Predicate = null)
You can find examples of using Nav 3D Agent in demo scenes located in the Demo folder of the resource.