Garry's Mod

Garry's Mod

Not enough ratings
Navmesh editing guide,So nextbots can play anymap.
By Zenlenafelex [PSF]
There are many maps that don't have a navmesh .A navmesh is a bunch of nodes that nextbots need to navigate a map.They tell nextbots for example where they can hide or where they should jump etc..This guide will cover all about nav generating and editing a mesh so nextbots can navigate any map you would like. This guide will go from the basic nav_generate to complex editing such as handling precise movement and complex jumps.
   
Award
Favorite
Favorited
Unfavorite
What is a navmesh?
Hello, In this guide i will show you how to create and edit the navmesh of a map so nextbots can navigate around the map.

What is a navmesh and why do we need it?

Nextbots don't have eyes like us so they can't see obstacles,So how do they know where to go?

Well they use a navmesh,
A navmesh is a set of nodes in the map that are all connected to each other.

The nextbots then search the connections for a path to their goal.
Once the path is found they will begin moving.

Here is an example of what a navmesh looks like.

[]










In the picture we see lots of squares.This is the navmesh.
These squares can also be called nodes or areas.

navmeshs don't have to be squares,They could be triangles or hexagons,
However valve has chosen to use squares.

The nextbots follow and cross each node until they reach their goal.

But wait,What if the map does not have a navmesh?
They will not be able to move around the map, Which is where this guide comes in.

In this tutorial we will take a look at generating a mesh.
We will also cover editing the mesh so nextbots can do advanced navigation.


Generating a navmesh
In this section we will generate a navmesh with a console command known as nav_generate

What is console?

Console is a developer window that allows you to type different commands into to trigger certain things.

Opening Console

If you don't know how to open console then do the following.

Go to your main menu, ( Not your spawnmenu )

Then click on
options

Then click on
advanced
Which is above and to the left of the OK button.

Then make sure the box that says ( enable developer console ) is ticked and press apply.

Now press the key to open console. ( On most keyboards ) its the button below Esc and to the left of 1

A grey window should appear.

It looks like this.

[]











And there you go,You have opened console.

Generating the navmesh

Imagine creating thousands of nodes per map.
That would take forever to do.

Luckily there is a console command to make it do most of the work for you.

( I say most of the work because sometimes it runs into problems which is why editing the navmesh after wards can really improve how nextbots navigate the map )


Anyways type into console the following command.

nav_generate


The game should start to lag heavily.Behind the scenes its creating all those nodes we talked about earlier.

Problems

No lag
If you find the game is not lagging at all.Then you might also see in console it say this
( No Valid Walkable Seed Positions )

To fix this simply type in console nav_mark_walkable
Then type nav_generate

It should then work.

Crashes
This one happends to me quite a lot. There's a few ways to get around this.

The first way is to copy the map across to another game and edit the mesh there.

The second is to load up a different gamemode instead of sandbox.

The third is to use nav_generate_incremental ( I will explain this command more in depth later )

Missing sections of the map
Sometimes the nav_generate command will miss sections of the map i will explain this in the next section which is about editing the mesh.


Editing the navmesh ( nav_generate_incremental )
While the nav_generate command does a pretty good job at creating a loads of areas.
Properly editing the mesh after wards can really improve nextbots.

In this section we will have a look at editing the mesh. ( Basics )

Lets begin simple.

Open up your console ( If its not already open )
If you don't know what console is then check the section above.

Now type into console sv_cheats 1
Then type nav_edit 1

You should see loads of squares or nodes or whatever you want to call them.
I will call these areas for now.

If you don't see any squares or nodes then the nav_generate command did not work or you have not done it yet.

Firstly we will begin simple.We will use nav_generate_incremental to create extra areas the navmesh missed during its generation.

nav_generate_incremental

nav_generate_incremental Creates more areas in a map without deleting areas that already exist.
For example if you type nav_generate in console again,It will delete all the areas that were there before. nav_generate_incremental Will not do this.Some areas it will.Such as jump nodes for example. ( Explained later in this guide )

I don't know why it deletes jump nodes but it can be annoying.

Anways, In this image the nav_generate command missed this area during its generating.
Well, I know. I just deleted them to show you an example.

[]





Anyways, As you can see,There is a big gap in the mesh.
So now we are going to fill in that gap with nav_generate_incremental


So,Put your marker over the empty space and type nav_mark_walkable
You should see this purple triangle like thing.

I will call it walkable seed.
It looks like this.

[]










Now all you need to do is type nav_generate_incremental
It may start to lag again as its creating more areas and handling all the visibility checks etc...


After it is done it should look something like this with glowing areas.

[]


The glowing areas seen in this image are the selected areas.
To deselect them simply type nav_edit 0 then nav_edit 1 In console.


Heres a quick tip with this command.

You can also use nav_generate_incremental_range to control how far it creates the areas.
Its default is 2000


Creating areas with nav_begin_area
nav_begin_area and nav_end_area allow you to create your own areas without using nav_generate_incremental all the time.

It can be handy for tricky jumps or precise movement explained later in this guide.

I have also used it myself in clever ways to trick nextbots into reaching an otherwise impossible ( for AI to get to ) point in the map.


Creating an area

To create an area hover your marker over the floor ( When i say marker i mean the crosshair )

Now type nav_begin_area

[]










Now you can move your marker to another point then type nav_end_area

[]











Great,Now we have created an area.
But there is one problem.Its not connected to the other area.

So lets connect it to another area.

Connecting areas with nav_connect


So,Hover your crosshair over the area you want to connect, Make sure its boarder is yellow.
Then, Type nav_mark

The area should turn blue like this.

[]




Now, Hover your crosshair over the other area and type nav_connect
This will connect the areas.

However its only one way.

To make it go both ways ( bidirectional )
Do the same steps we did above but this time we use nav_mark on the other area and nav_connect on our area.

For example.

A: nav_mark
B:nav_connect

B:nav_mark
A:nav_connect


Now the dark blue line should turn light blue.

[]


And there you are,You have created your own area and connected it.
Using nav_connect you can make bots or nextbots only go on a certain path one way.
This is handy for example with tricky jumps.



nav_splice

Before we finish this section lets have a look at a very powerful tool known as nav_splice

nav_splice can create ramped areas like stairs with ease.It will also auto connect the areas you spliced.

To use it simply use nav_mark as explained earlier and then nav_splice on the other area to use it.

[]





More editing tools
Lets have a look at some more editing tools.

This section assumes you know how to nav_mark an area then invoke the commands below.
See the section above for how to use nav_mark

nav_split

With this command,You can split areas.
hover your crosshair over the area. ( You should see a line ) then type nav_split

[]

Before splitting an area.

After splitting an area.


nav_delete

You can remove any area you don't want.


nav_disconnect

Use it the same way a nav_connect ( explained in the section above )
It will remove a connection between two areas.

nav_mark_attribute

This will mark areas with a specific attribute for example.You can set different attributes like jump to tell nextbots to jump.

Keep in mind some attributes like jump nextbots may ignore while others may not.
It really depends on the coder of the nextbot.

For example i created the player bots in smashing survival gamemode, They will respond to this and jump but they will ignore precise.


nav_analyze

You normaly use this command once you are done editing a navmesh.
Firstly you will save it then you will type this command.

I believe it will delete jump areas so keep that in mind, Create the jump areas last.
It will do the finishing touches like adding extra sinper and hiding spots.

What are those? Lets have a basic look in the next section.


Hiding and sniper spots
Hiding and sniper spots are spots in the map which nextbots and player bots use to hide or snip from hence their names hiding and sniper spots.

Hiding spots are green and sniper spots are purple.
The only way to add them from what i know is to use nav_analyze

Here is an image with hiding and sniper spots.
They are the green and purple lines in the corners.

[]
Ladders
Ladders are only usable by player bots.
Only very advanced nextbots will be able to climb them.

To create a ladder hover you crosshair over the front of the ladder until it goes green.
If it does not go green then that can not be made a ladder.

If it is green then type nav_build_ladder

[]



If the ladder is facing the wrong way type nav_ladder_flip
Controlling bots movement
What if,There was a way you could make a bot walk in an area, Or maybe make them jump.

Well you can do that with nav_mark_attribute

nav_mark_attribute is an easy way to mark areas with specific attributes.
You can have multiple attributes on a single area at once.
Player Bots like the onces in the smashing survival gamemode may struggle however.
But normal nextbots should be fine.

Again,Keep in mind some nextbots will not respond to certain attributes as explained earlier,It depends on the creator of them and if they have coded that in.

Now, You don't have to use nav_mark_attribute to set the attributes but its easier in my opinion.

Here is a list of them.

nav_jump

Tells the bot that they need to jump while on this node.

nav_no_jump

This is mainly used for player bots.
Sometimes bots will jump a lot on stairs and ramps.
To prevent that you can use this command.

nav_avoid

Bots will try not to enter this area unless the original path has become to dangerus.

nav_precise

This is used in precise movement.Such as handling complex jumps and navigating in tiny space.
Here is a picture.

[]


As you can see,I have used precise on the nodes connecting to the pipe to make them enter it easily.


nav_transient

I don't think any gmod nextbot coder will use this,But basicly it tells the bot that this area may become blocked and it needs to be checked often.

For example you might have part of the map where a ceiling collapses and blocks the other places in the map.



Final editing steps
After you are happy with your navmesh, You should save it.

Use nav_save to save your work.There is no undo button in the nav editing so its important to save often.

After saving it. Use nav_analyze

This will check the mesh and add extra hiding spots sniper spots etc...

Keep in mind nav_analyze will delete nav_jump areas so its best to add those after wards.

After all that,Type nav_edit 0 and there you go you have completed the mesh.
Advanced Navigation
Now in this section i will show you some advanced navigation tricks.

we will assume you know how to edit a navmesh now from previous sections of this guide.

Let me show you some complex navigation examples.
Then after that,I will show you some tips and tricks you can do.

Jump pad example

In this image.I have used nav_splice between the top and bottom area over the jump pad so
bots will use the jump pad.

I have also used nav_precise to help them move roughly into the center of the area to help them align the jump.

Then with nav_no_jump they will not jump so they don't go too high when using the jump pad

[]



Launch pad example

Here is a similar example to the jump pad example.

I created an area right at the top of the launch pad and nav spliced it to the bottom areas.
I then deleted the top area and merged the spliced areas togeather as one.

I then nav spliced the ramp to the bottom area and nav_disconnected it to the ramp.( Creating a area in mid air )


Then using nav_connect from the ramp to the area in mid air ( Connected to the ramp and bottom area )
Created it as a one way connection so nextbots don't get confused.

With some nav_no_jumps on the ramp to prevent nextbots jumping over the bottom platform.

[]




Tips and Tricks

Here we will look at some tips and tricks you can do with the navmesh.

Easy dropdowns

This trick is simple.
This trick is best used by player bots but it should work the the normal nextbots.

[]


As you can see here we have a normal drop down.
With this dropdown you can make it even easier for nextbots/Player bots to jumpdown by extending it to the next area.

Here is an example, Compare above to now.

[]


As you can see we have made it less straight down.
This can make it easier ( mostly for player bots ) to jump down.


Smart jumping

In this image we see a node on top of a box connected to a node on the ground.

[]


Rather than that,We could disconnect it and use nav_splice
After that we can mark it with nav_jump

Compare above to now.

[]


This is not only a bit easier for player bots to jump but also it is much neater too.

Ladder Tip

You can use nav_begin_area and nav_end_area on ladders as well.
Useful for things such as making bots jump off of ladders at a certain point.

Thats everything for now. I will add more stuff to this section soon.

Outro
Well, Thank you for reading this guide.

I am a Lua developer and i have spent so long working and designing nextbots in gmod.
For example if you have played smashing survival gamemode.
I created those bots.

Their AI and navmesh navigation is very old now since they don't have the complex corner cutting my new bots use.

Feel free to post this around or rate and favourite if you like!

Have Fun!
8 Comments
Deadmau5UltraAnimals 8 May, 2023 @ 9:57am 
Excellent guide. Using this since there's maps in Insurgency but no navmeshs for many custom maps, Think i have to learn from scratch how to make
Zenlenafelex [PSF]  [author] 8 Oct, 2021 @ 3:58am 
@Slen.exe

Yes, Sorry for the slow reply, I gave an answer to your second comment on my profile if you are still having problems, I hope it helps!
Slen.exe 8 Jul, 2021 @ 9:28am 
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...
Zenlenafelex [PSF]  [author] 10 Sep, 2020 @ 3:13am 
Your all welcome! :)
khalil 5 Sep, 2020 @ 12:50am 
Very Helpful! Thank You
Vroooooom 20 Mar, 2020 @ 6:20am 
Yeah, i got stuck at step 1:
Generating a navmesh takes apr. untill bedtime.
donycoe 17 Mar, 2020 @ 12:31am 
I messed with nav meshes in left for dead once... Bots are dumb. Nice guide.