S&box Wiki

Revision Difference

SettingUpANavigationMesh#551257

<cat>Hammer.Basics</cat>⤶ <title>Setting Up A Navigation Mesh</title>⤶ ⤶ # What is a Navigation Mesh (Navmesh)?⤶ ⤶ A navigation mesh is a bunch of precalculated shapes compiled with a map that let NPCs and other entities navigate around.⤶ ⤶ # How do I add one?⤶ ⤶ 1) In Hammer, in your map, create a `func_nav_markup` entity somewhere where you want the navmesh to be generated (it just has to be in a small part, it doesn't have to cover the entire area).⤶ ⤶ <upload src="b0cef/8db8a32cfb98b2e.png" size="565870" name="8db8a2b6c33d614.png" />⤶ ⤶ 2) On that entity, make sure `Walkable Seed` is ticked.⤶ ⤶ 3) Build your map with `Build nav` enabled, and you are done.⤶ ⤶ # Navmesh Hulls⤶ ⤶ Navmesh hulls represent that fact that different NPCs might have different sized "hulls". Imagine a cat, a human and an elephant - they are all different sizes of creature and so are able to navigate different kinds of spaces.⤶ ⤶ You can configure the hulls in Hammer by going to `Navigation` and ticking `Use Custom Generation Params`, but you usually don't need to. The default hull used is hull 0 which is the medium-sized hull (for humans and such).⤶ ⤶ You can control which hull is used through code:⤶ ⤶ ```⤶ var path = NavMesh.PathBuilder( myStartPosition )⤶ .WithAgentHull( NavAgentHull.Agent1 ) // The default is NavAgentHull.Default (hull 0).⤶ .Build( myEndPosition );⤶ ```⤶ ⤶ # Nav Preview⤶ ⤶ Once you have added the `func_nav_markup` you can preview what your navigation mesh will look like in Hammer by going to `Navigation` -> `Nav Preview`.⤶ ⤶ <upload src="b0cef/8db8a2bfb795eba.png" size="87014" name="image.png" /> ⤶ ⤶ The preview shows the passable space of each hull as a separate shade of blue.⤶ ⤶ Generally the preview should match how your navmesh behaves in-game, but if you are encountering problems, you can double-check by using the command `nav_edit 1` in-game. You can then cycle through the different hulls by running `nav_select_hull 0`, `nav_select_hull 1` and `nav_select_hull 2`.⤶ ⤶ <upload src="b0cef/8db8a3214b59b56.png" size="423269" name="image.png" />⤶ ⤶ ⤶ ⤶ ⤶