Modifying the level to support AI

Alright! Now we can place all the puzzle pieces together by modifying our level to support our AI character. That means we have to adjust the size of the floor (as it is too small for both the player character and the AI character at this point) and place a NavMesh in the scene.

Let's start by adjusting the floor size. Within the world outlier, select the Floor StaticMeshActor. Address the Details panel and change the Scale property of the Transform section so that each axis is set to 8. This will give us a large enough area to run around in. Now we need to generate a navigation mesh for our floor so our AI can pathfind properly.

What is a navigation mesh

A navigation mesh is a generated mesh that acts as an area (defined by the polygons of the navigation mesh) for the AI to path within. Navigation meshes, or NavMeshes for short, are generated within the bounds of a Navigation Mesh volume. They can support slopes, obstacles, rough terrain, and much more. The idea is the generated mesh will conform and contour to any regions the AI can path to, we can then query this generated navigation mesh for pathing points the AI will follow.

When generating a NavMesh, the engine will take into account the size of the AI that will be maneuvering the mesh. This is because as an AI agent's size increases, the regions within which they can path will decrease proportionally. We need to be able to inform the engine of the size of our AI agents beforehand so the NavMesh is generated appropriately.

Adjusting the NavMesh generation settings

As our AI is quite large we are going to have to place a NavMesh into the scene that supports the size of the AI character's collider. To do this we are again going to have to change some project settings. Navigate to Edit | Project Settings. Once here, navigate to Engine | NavigationMesh. As our character has a capsule radius of 160 and a capsule height of 320, we need to allow navigation mesh generation to support this capsule size. Under the Generation section of the NavigationMesh settings page, change the AgentRadius property to 160, the AgentHeight property to 320, and the AgentMaxHeight property to 340. This will ensure the navigation mesh will be able to generate a mesh that supports these values. The settings should appear as follows:

Adjusting the NavMesh generation settings

We are not done yet as we need to still add our Boss AI capsule dimensions to a list of supported agents to the navigation system, so that the correct navigation paths will be generated for our boss AI. Within the project settings, navigate to Engine | Navigation System. Within this settings page we need to add an element to the Supported Agents array under the Agents category. You can do this by clicking the small white plus. Once an element has been added to the array you can expand the settings by clicking the small arrow on the left-hand side of the property. Then do the same for the entry 0. Within these settings, change the Name property to Boss, the NavAgentRadius property to 160, and the NavAgentHeight property to 320. The settings will appear as follows:

Adjusting the NavMesh generation settings

Placing a NavMesh in the scene

Now that we have adjusted the NavMesh generation properties we need to generate a NavMesh in the scene. We will do this with a NavMeshBoundsVolume object. This object defines a volume within which the engine will generate a navigation mesh for each supported agent listed in the Supported Agents property of the Navigation System Settings page. These generated NavMesh are called RecastNavMeshs. Navigate to the level editor and, within the Modes panel, search for a NavMeshBoundVolume and drag this volume into the now by selecting and dragging the Modes Panel entry.

Select this new NavMeshBoundsVolume entry in the WorldOutlier and ensure that it is situated around origin. Then scale the volume so that it encompasses the entire floor mesh and scale the height of the NavMesh so that it encompasses a large vertical area. The transform for my NavMeshBoundsVolume appears as follows:

Placing a NavMesh in the scene

With the NavMesh in the scene you will see another entry in the WorldOutiler, RecastNavMesh-Boss. This is the actual navigation mesh that has been generated within the NavMeshBoundsVolume. This one has been generated specifically for the Boss agent entry we added to the Supported Agents list earlier. If there were more SupportedAgents there would be more RecastNavMesh objects in the level. To see the generated NavMesh, simply press the P key. Everywhere that is green is where our AI will be able to path to. Anywhere that is red is blocked or still generating, and anywhere without color is where the AI cannot path to. Feel free to add some obstacles to the scene by dragging in Cube objects from the ModesPanel. I chose to drag in a couple and scale them like so:

Placing a NavMesh in the scene

As you can see, the NavMesh has updated so that the areas closest to these obstacles cannot be pathed to, this will avoid any unwanted collisions during AI pathing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.138.104