Generating Off-mesh Links for AI in Unity

Jared Amlin
Geek Culture

--

Using off-mesh links is how you can tell your nav mesh agent what areas can be accessed by jumping, hurdling or opening a door for example. This short article shows how to set this up on your NavMesh.

Off_Mesh Links

Here we have an area with waypoints that are of the beaten bath.

By default, you have Navigation Area options for walkable, non-walkable and jump.

The Areas tab is where you can add in additional area types.

You will need to bake your NavMesh again once these areas are setup. The Drop Height and Jump Distance dictate how far of a gap or how far of a fall the agent is allowed to take.

These objects need to have the Off Mesh Link component added to them in the inspector.

While this will handle moving the agent to the off mesh link, it won’t change your animation state. While there are some different approaches you can take here, this is one way to check if your agent is on an off mesh link, and check the type of Area before playing animations.

if (_agent.isOnOffMeshLink)
{
var meshLink = _agent.currentOffMeshLinkData;

if (meshLink.offMeshLink.area == NavMesh.GetAreaFromName("Jump"))
{
//set animation state
}
}

Here is the clown making a jump across to a waypoint on an off mesh link.

Obstacles

You might also want to have obstacles, like a wall for instance, that you want to the AI to avoid.

Select the obstacles in the hierarchy, set them as Navigation Static and re-bake the Nav Mesh.

Here you can see that the Nav Mesh now moves around the obstacle.

Here is the clown avoiding the new obstacle when moving between waypoints.

That’s it for this intro series into Nav Mesh and Nav Mesh Agents. Thanks for reading!

--

--

Jared Amlin
Geek Culture

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.