Generating Off-Mesh Links in Unity 2021
In this article we’ll bridge the gap.
Literally.
Some initial setup using the same AI project we’ve covered in previous articles.
Duplicate Floor2, rename it, and move it so that it does not connect to Floor2.
Duplicate Point_F, rename it, and move it on to Floor3.
If we run our game, we can see that the AI attempts to move towards the last waypoint, but cannot cross the gap.
If we check our Navigation window, we can see that our NavMesh is set with a Jump Distance of 0.
Obviously, any gap, including ours is going to be more than 0, so the AI is unable to cross over to the last waypoint.
To enable our Floor3 game object’s NavMesh to create and Off-Mesh Link, we need to add the “Off Mesh Link” component to it.
On our Nav Mesh Link component, we want to drag the Point_F game object to the “Start” field and the Point_G game object to the “End” field.
We can also enable “Auto Update Positions” though it should work without that.
Last, set the “Navigation Area” to Jump.
Running our game, we can see that the AI will indeed jump the gap!
If we go back to the Navigation window > Bake section and click “Bake”, we’ll see a path shown in the Scene view for this off-mesh link.
And there you have it, we’ve created a jumpable gap for our AI!