Garry's Mod

Garry's Mod

59 ratings
Navmesh Tutorial (Guess Who Maps)
By lolleko and 1 collaborators
This guide will explain you how to modify a Nextbot navmesh.
This guide cointains infomration on how navmeshs behave and are edited.
But also some more detailed information related to my gamemode Guess Who.
   
Award
Favorite
Favorited
Unfavorite
Introduction
In this section I will explain what a navmesh is and why it is needed for my Gamemode http://ad.gamersky.info/@steamcommunity.com/sharedfiles/filedetails/?id=480998235

A Navigation Mesh represents the "walk-able areas" of a map. This data is required by Bots and Hostages in Counter-Strike: Source and Counter-Strike: Global Offensive, AI Bots and the Horseless Headless Horsemann in Team Fortress 2, and Bots and Infected in Left 4 Dead and Left 4 Dead 2, allowing them to "know" how to move around in the environment.
Navigation Mesh data is stored in a NAV file corresponding to the map file (.bsp) for which it is used. For example, the nav mesh for cstrike\maps\de_dust.bsp is stored in cstrike\maps\de_dust.nav.

Source: https://developer.valvesoftware.com/wiki/Navigation_Meshes

So basically any form of bot needs this mesh for navigating, so do the bots in my gamemode.
While most of the techniques I'm going to explain are quite similar to those described in the Wiki article and I definitely recommend you reading this article, navmeshes for Guess Who need to be edited a bit differently.

So first of all in the current state of Guess Who the Bots are limited, they cannot climb ladders, they will sometimes get stuck in tight or crowded areas and jumping is still a bit limited. You should keep that in mind when choosing a map you want to create a navmesh for because maps with a lot of ladders or many floors will rather work bad.

That's why I explain here how to make your navmesh in a way the bots don't get confused or stuck.
1. Commands & Navmesh Generation
For a Command Reference i once again refer to this article: https://developer.valvesoftware.com/wiki/Navigation_Meshes

Some of the commands in this guide you will have to use repeatedly so I recommend setting a bind for them. I personally binded nav_delete, nav_mark, nav_disconnect and nav_split to keys.

If you don't know what a bind is, it's basically a key you can press to execute a console command without typing the command every time. To create a bind type into console:
bind "KEY" "CMD" e.g. bind "O" nav_delete
I suggest you setup the same binds as me to start with you can change or remove them later if you want to.

Now that you setup the commands your ready to load up the map, for that you just normally click on start game and select your map, the gamemode isn't really relevant but to start editing i suggest just plain Sandbox.

In this guide i will create the navmesh for cs_italy as an example.

Once your done loading you want to type in your console
nav_edit 1
To open the navmesh overlay you should now see a small 3D coordinate system at your cross-hairs position.

After that you want to look at a walkable surface in most cases you can use the ground beneath your spawnpoint and type
nav_mark_walkable
You should now see a purple mark at the point you looked at.


This will serve as the startpoint for the navmesh generation.

Then you want to initiate the generation.
nav_generate
Depending on the map size and your PC specs this may take a while.

Once It's done the result should look something like this:


Your navmesh is already usable, but the auto generated ones are pretty bad and should be edited, in the following sections I will go over changes you should make to improve the behavior of the bots.
2. Fencetops
Fencetops are areas on top of fences rails and similar surfaces. The bots don't like those areas and while they could probably make those jumps it will rather look buggy and not human like.
I recommend you deleting all the fencetops areas on a map. For that you will need the following command
nav_delete
or your bind if you set one up.
Once your done editing a certain area you should save your progress with
nav_save
so you can reload it with
nav_load
in case you messed something up or deleted a area by accident.

Here are some examples of those areas and how they look after deleteing them.


3. Blocked Areas
Sometimes the auto generation will generate areas under objects and therefore marks them as walk-able for bots even though they can't walk through the object. Once again you need to delete this areas and leave a clear space around those objects so bots can evade them. Most often you will see this at corners of rails.
This also applies to poles too!
4. Unwanted Connections
Connections are those dark blue and light blue lines between areas. A dark blue line is a one way connection and a light blue line works in both directions.
Sometimes the auto generation will generate connections that shouldn't exist, they should be removed, for that you need to look at the first area and type
nav_mark
the area you looked at should now have a light blue outline. After that you want to look at the connected Area and type in
nav_disconnect
Those areas are again most common at railings.
Drops that should be a one-way connection but are a two-way for some reason.
5. Unreachable Areas
There will be some areas on top of objects or walls that are not reachable by bots, they should be removed as well. If you're not sure if an area is reachable it is better to remove it than keeping it.

Examples



6. Props
The auto generation will only recognize brushes (solid walls, floor and ceilings) and static props.
Therefore there will be a navmesh beneath normal props that are affected by physics (prop_physics). My bots will push small props away if they come in contact with them. Anything that is as big or smaller than a barrel should not be treated special while editing.
So something like this is perfectly okay:


Bigger props like tables and cupboards should have no navmesh areas beneath them.

7. Doorways (tight areas)
Tight areas and especially doorways should have more small areas, so the bots can navigate through them without getting stuck. The area in a doorway should only be connected to small areas of the same size. If you have one large area leading to a tight doorway the bots will try to walk through corners.
You can use
nav_split
to split the area you loooking at at the white line.


7.1 Corners
Areas shouldn't be to close to corners once again the bot will try to shortcut and walk into the corner. You can remove those areas in most cases or split them into smaller ones.


7.2 Large Areas
Although this is not required i recommend splitting the bigger areas into smaller ones so bots do not choose the same path when navigating through them.
You can just split them with
nav_split

8 Drops
In contrast to jumps drops can be safely placed anywhere between areas.
To create a drop you need to create a one-way connection between to areas.
You mark the first area with
nav_mark
Look at the one you want to connect and type
nav_connect
You should now see a dark blue line

9. Jumps
Jumps can be up to 50-60 units high, the bots will detect them automatically, but I don't recommend having to much connections to different elevations jumping looks buggy and may not always work.
10. Saving and Analyzing
Once you are done editing the navmesh you want to save it via
nav_save
we save here just in case the analyzing crashes. You can start it with
nav_analyze
This will take some time depending on mesh size and PC specs.
Once It's done I like to save it again just to make sure everything worked.
The console output now should be just navmesh saved... without any errors.
The .nav file is saved in your GarrysMod/garrysmod/maps/ directory and called mapname.nav.

How do i know my navmesh is good?

You can load my gamemode and let the npcs walk around for a bit, you will see if and where they get stuck. Also you will receive this console error:

"Nextbot [][] Got Stuck for over 15 seconds and will be repositioned, if this error gets spammed you might want to consider the following: Edit the navmesh or lower the walker amount."

If you just use the auto generated navmesh this error will get spammed a lot. After editing the error count should decrease. So the fewer errors you get the better your mesh.

You can't get rid of this error completely since npcs getting struck isn't 100% navmesh dependend.

You can also check out my finished navmeshs when you load up a map listed on the gamemodes workshop page with the gamemode enabled.

Publish your meshes

Creating and editing a mesh is a lot of work, so it would be great if you share your mesh on the workshop or https://garrysmods.org/.
13 Comments
>[DEMIG] EFC 3 Jul, 2023 @ 5:53am 
In hammer i make 8 by 8 stairs and nav mesh wont generate there i need help
Deadmau5UltraAnimals 8 May, 2023 @ 6:51am 
to disable navmesh lines you probably would set nav_edit back to 0
Nickers 24 Mar, 2023 @ 8:32pm 
How do you publish it?
L4D34D 3 Dec, 2022 @ 4:58pm 
how do disable navmesh debug lines?
tailstheultraswag 6 Mar, 2022 @ 3:53pm 
@Slen.exe i think you either have too many addons or the map is too big and detailed.
Slen.exe 8 Jul, 2021 @ 9:30am 
Hello, I have a problem with nav_generate. The game crashes after some compilation time. How can I fix this? Maybe the problem is in the map? If so, what is it? Please help...
Jamz999 28 Jun, 2021 @ 6:14am 
@LomboLombinho Doing Nav_generate again will delete your entire mesh.
FunTon's 600lb Lumber Tumbler 16 Apr, 2021 @ 3:09pm 
Question:
Sometimes with editing nodegraphs I do some upper areas but I dont link it with other places that make it unaccessible, would it be possible to place a navmesh on top of something like a shipping container without the bots thinking they can just walk up there?
LomboLombinho 4 Oct, 2020 @ 2:59pm 
Is there a way for deleting entirely the navmesh?
ItsRikoVR 6 Jan, 2018 @ 1:40pm 
Thanks for the response!