Objective: To allow our AI Agent to bridge gaps in floors using OffMesh Links in Unity.
Here we can see above that we have a platform next to the last waypoint, but the AI Agent is unable to reach it because there is no NavMesh surface to walk on. How do we solve this issue? Offmesh Links!
Building the Offmesh Link
First we need to make sure that we rebake the new platform into the scene:
Next, I am going to add the ‘OffMesh Link’ component to the new platform:
Here, we need to provide a starting point and an end point, which in my case will be — waypoints F and G.
Note: Beware of where you place the game objects on the Y-axis as the AI Agents trajectory is calculated from it’s base and usually targets the centre point of a primitive game object (it’s pivot point), resulting in an upwards vector followed by a short snap to position as shown below:
Notice the red lines projection from the base of the AI Agent to the middle of the cube.
How to Solve
Make sure the game objects pivot point is on the same level of Y-axis as the AI Agent:
Building a NavMesh — Unity Documentation
NavMeshAgent — Unity Documentation
NavMeshAgent component — Unity Documentation
Creating an OffMesh Link Manual — Unity Documentation
OffMeshLink Component — Unity Documentation
Setting Up a NavMesh in Unity — Article
Moving Agents on a NavMesh in Unity — Article
Creating a Looping NavMesh in Unity — Article
Using a Finite State Machine to Create Smart AI in Unity — Article