2 min read

Nav meshes for small and large AI agents

Nav meshes for small and large AI agents

The first boss fight in Terralysia is more or less done and I’m very excited to ship this to players. I think it’s going to be fun, but be warned, it’s going to be brutal…like the rest of the game.

If you’ve finished the demo you may have seen the tease for the boss. If you haven’t, I will spoil it for you. It’s the Spider Queen.

While implementing this boss fight I ran into an issue. The Spider Queen is much larger than any other monster I’ve added to the game so far. This isn't strictly a problem, but there are a few edge cases where the AI pathfinding becomes troublesome.

In Unreal Engine AI navigates by traversing a nav mesh, a set of polygons that define the surface where it’s safe and accessible to walk. This nav mesh is baked offline (though you can update it at runtime as well for a cost) and takes into account various parameters, like how big the agent using it is.

The size of an actor is what decides if they can fit on the nav mesh, so the nav mesh needs to know how big the agents it supports are. Because our nav mesh was made for our smaller monsters, it causes the big Spider Queen to get stuck on obstacles, thinking it can fit in gaps where she obviously can’t.

The radius of the agent is used to decide how close to obstacles the navmesh can be placed so actors don’t intersect the obstacle. This becomes a problem when you have two types of agents with a significant difference in size, like we do.

Luckily, Unreal Engine has a solution for this. You can specify different types of agents to support, which essentially creates multiple versions of the nav mesh. This has a cost, obviously, but in our case we only need two types (for now): one for small monsters, and one for the boss.

With this setup our smaller monsters pick the default nav mesh, which allows them to traverse narrower areas, and the boss picks the second nav mesh that blocks certain paths. The result is both small and large monsters traverse the level as expected.

0:00
/0:18

Stay tuned for news, you’ll be able to fight the Spider Queen soon enough!