Apex Path Examples
This example shows basic navigation in a scene with a few obstacles. The agent uses the Quick Start Navigating Unit with Selection component and the layers for blocks and terrain are correctly set up in the Layer Mapping component.
Doors (using the Door as Dynamic Obstacle)
This example shows how the use of attributes can allow one agent to open the door, while the other agent cannot.
OrangeAgent has the attribute “On Orange Team” set on the Unit Component. The PatrolBehavior of OrangeAgent is set to linger at patrol nodes to ensure that the agents’ patrol routes are not synchronized. The door has the attribute “On Orange Team” set on the Dynamic Obstacle component.
Consequently, OrangeAgent ignores the door when searching for a path. The door, however, does not open by itself. To avoid OrangeAgent trying to path through a closed door, the DoorToggle gameobject has a DoorSlider component that responds to any collider entering with an attribute of “On OrangeTeam”. The SphereCollider attached to the DoorToggle gameobject is set to trigger equal true for this purpose. In the door slider component the “Door” attribute is set to the door gameobject. Note that GreenAgent can get a path through the door when the door is opened by OrangeAgent.
Doors (using the Doors One Way
This example shows how to use attributes and attribute triggers to create a door that can only be opened from one side.
GreenAgent has a patrol route that takes the agent into the room through the top-right door (named “NormalDoor“ in the hierarchy) and then out from the room through the bottom door (named “OnewayDoor” in the hierarchy). The agent starts by entering the room through the “NormalDoor” door in the top-right corner. The agent already has the attribute “On Green Team” set on the Unit Component.
The Dynamic Obsctale component’s “Exceptions” property on the top-right door is set to “On Green Team”. This allows the agent to get a path that goes through the door. The DoorSlider component on the DoorToggleNormal gameObject opens the door when the agent approaches.
Inside the room is an Attribute Manipulating Trigger component on the InsideRoom gameobject. This component adds the attribute “Special Doors Available” to the agent’s Unit Component when the agent exits the collider (note that the “Update On” property is set to “OnExit”). The Dynamic Obstacle component on bottom door has the “Exceptions” property set to “Special Doors Available”.
The mechanism is thus that when the agent exits the collider on the InsideRoom gameobject, the agent gets the “Special Doors Available” attribute added to the Unit Component. With this attribute the agent can now get a path through the one way door at the bottom and the DoorToggleOneWay opens the door for the agent. Note that both the DoorToggleNormal and the DoorToggleOneWay have Attribute Manipulating Trigger components that remove the “Special Doors Available” attribute when an agent exits the collider. The mechanism is thus that the agent can only get the “Special Doors Available” attribute that is required to open the door inside the room, and the attribute is removed whenever the agent leaves the room.
Moving Dynamic Obstacles
This example shows how an agent avoids a moving dynamic obstacle solely by replanning the path and fleeing from the dynamic obstacle if necessary.
The moving dynamic obstacle has a cone in front of it based on its velocity. The cone blocks nodes in front of the dynamic obstacle when it moves. Orange replans the path it has received if the path has become blocked by the cone from the moving dynamic obstacle. OrangeAgent also has a Flee Obstacle component attached. If the component registers that the node the agent is in is blocked from e.g. the agent suddenly being in the cone from the dynamic obstacle, the agent flees from the cone at full speed to the nearest empty node. Note that this is not the optimal way to solve obstacle avoidance, but shows how dynamic obstacle avoidance can be achieved by replanning and a fleeing behavior.
The example shows how moving dynamic platforms can be created. This example shows the potential of using the wait and resume functions of the pathfinder to create advanced pathfinding mechanics.
The bridge contains a platform and three sensors. The agent gets a path across the bridge and starts moving along this path. However, when the agent enters the SouthSensor collider the WaitForPendle component calls the ObjectPendler component on the Platform gameobject. As a result of this the platform starts moving towards the agent. The WaitForPendle component also tells the Steer for Path component on the agent to wait. When the platform arrives the agent continues its path towards the other side of the bridge, but the agent is told to wait at the center of the Platform gameobject when the agent enters its collider. The platform moves to the other side of the bridge. When it arrives the agent is told to resume its path. The NorthSensor has the same function as the SouthSensor and is used when the agent is returning to the original side of the bridge.
This example shows how to use patrol routes to create patrolling agents.
Each agent has a Patrol Behavior component attached that moves the agent across the patrol route set in the “Patrol Route” property. The patrol routes are defined in the “Patrol Route” gameobjects under the “GameWorld” gameObject in the hierarchy. Each Patrol Route gameobject has a Patrol Route component attached. This component is a collection of Patrol Points that together define the patrol route.
Portals are short cuts within a grid or a connection between grids.
Apex Path ships with a Teleporter portal and it is trivial to make your own.
Wander Performance Test
This example shows the performance of Apex Path using hundreds of agents and multiple dynamic obstacles.
Each agent has a Wander Behavior component attached and wanders to a random destination within the distance set on the “Radius” property on the Wander Behavior. Dynamic obstacles are instantiated at random positions and fall to block the agents’ paths. The agents replan their path as the path becomes blocked.
Basic Height Maps
This example shows how the Basic Height Map component can be used to generate height maps for scenes that required three-dimensional navigation. The Basic Height Map component is added to the GameWorld gameobject and provides height data for the agents when they navigate. Agents can both use physics to scale ramps and ledges with deceleration and acceleration or can be kinematic for an even speed. Granularity and Maximum Slope Angles can be used to adjust what ledges and slopes are walkable.
This example shows how path smoothing works. The green agent to the right doesn’t use path smoothing. The path is jagged around corners and go from cell center to cell center. The orange agent to the left uses path smoothing. The path is linear from the agent to each corner node.
Terrain Height Map
This example shows how height maps work using the Unity terrain engine. The Terrain Height Map component is added to the GameWorld object. The Terrain Height Map component is updated using the “Update Grids” button. The grid generated can be visually debugged by setting the draw mode to “Accessibility” on the Grid Visualizer component.