Difference between revisions of "L4D Level Design/Nav Meshes"

From Valve Developer Community
Jump to: navigation, search
m (Splitting Nav Areas)
(Section 7 - Nav Meshes)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{otherlang2
 
{{otherlang2
 
|pt-br=L4D_Level_Design/Nav_Meshes:pt-br
 
|pt-br=L4D_Level_Design/Nav_Meshes:pt-br
 +
|zh-cn = L4D关卡制作/导航网格
 
|fr=L4D Level Design/Getting Started:fr}}
 
|fr=L4D Level Design/Getting Started:fr}}
  
Line 95: Line 96:
 
== Splitting Nav Areas ==
 
== Splitting Nav Areas ==
  
You will also notice that the Nav Mesh in your level currently has large areas that cover the entire room. Sometimes it's necessary to split those large areas into smaller ones. For example, if you want to add an attribute like where the survivors start and you want the area to be right in front of the weapons table.
+
The Navigation Mesh in your level currently may have large areas that cover the entire room. Sometimes it's necessary to split those large areas into smaller ones. For example, adding an attribute at where the survivors start, but you only want it at the area in front of the weapons table.
  
 
You can split up nav areas by using "<code>nav_split</code>".
 
You can split up nav areas by using "<code>nav_split</code>".
Line 111: Line 112:
 
[[Image:l4d_nav_split_02.jpg|thumb|caption|right|400px|Performing a nav_split.]]
 
[[Image:l4d_nav_split_02.jpg|thumb|caption|right|400px|Performing a nav_split.]]
  
Press {{key|Insert}} to perform the split.
+
Then, press {{key|Insert}} to perform the split.
  
 
{{clr}}
 
{{clr}}
Line 119: Line 120:
 
Now, position the cursor so that the new area you just split in front of the weapon table is split in half in the other direction.
 
Now, position the cursor so that the new area you just split in front of the weapon table is split in half in the other direction.
  
Press {{key|Insert}} to perform the split and see the result.
+
Press {{key|Insert}} again to perform a second split and see the result.
  
 
{{clr}}
 
{{clr}}
  
 
== Adding Attributes ==
 
== Adding Attributes ==
 +
Nav areas may be marked with ''attributes'' that designate specific purposes, some being essential. For example, the<code style="color:#E5E5E5; ">EMPTY</code>disallows common infecteds to spawn on it, and lets them not spawn on weird areas, like a kitchen counter. In our navigation mesh, we need to mark an essential attribute, the<code style="color:#E5E5E5; ">PLAYER_START</code>attribute, which designates where the Survivors should start for the campaign's first map. Let's mark the area in front of the weapon table that we just split with the attribute.
  
Nav areas may contain ''attributes'' that designate specific purposes. For example, a nav area marked with the attribute "EMPTY" means that a common infected cannot spawn on it. Let's say that you have a kitchen with a counter in it, and you don't want infected to be standing on the counter top when the player gets there because it looks weird. You can mark this area as "EMPTY".
+
{{clr}}
 +
[[Image:l4d_nav_attribute_01.jpg|thumb|caption|right|upright=1.2|Selecting a nav area with <code>nav_toggle_in_selected_set</code>.]]
  
First, enter the "<code>z_debug 1</code>" command to allow the attributes to be viewed.
+
Start by visualing the attributes using the<code style="color:#E5E5E5; background-color: #202020;">z_debug 1</code>console command, then point your cursor at the area and use<code style="color:#E5E5E5; background-color: #202020;">nav_toggle_in_selected_set</code>by pressing the {{key|Z}} key.
  
In our first nav mesh that we're creating, we need to designate where the Survivors are going to start when they appear in the map. Let's mark the area in front of the weapon table that we just split as "PLAYER_START"
+
{{clr}}
 +
[[Image:l4d_nav_attribute_02.jpg|thumb|caption|right|upright=1.2|A nav area marked with the PLAYER_START attribute!]]
  
Point your cursor at the area in front of the weapon table and use "<code>nav_toggle_in_selected_set</code>" by pressing the {{key|Z}} key.
+
After selecting the area, use<code style="color:#E5E5E5; background-color: #202020;">mark PLAYER_START</code>by pressing {{key|Enter}} after typing it. The selected area will then turn purple, meaning now Survivors start on this nav area at the start of the campaign.
 +
{{tip|To remove attributes, select the area and use<code>clear_attribute ''[attribute's name here]''</code>in the console with the respective attribute name. You can also remove all attributes in a map by not selecting any nav areas when using the command.}}
  
[[Image:l4d_nav_attribute_01.jpg|thumb|caption|left|400px|Selecting a nav area with <code>nav_toggle_in_selected_set</code>.]]{{clr}}
+
{{clr}}
 +
[[Image:l4d_nav_attribute_03.jpg|thumb|caption|right|upright=1.2|In the second room, and selecting its navigation area.]]
  
Now bring down your console and type "<code>mark PLAYER_START</code>" and press {{key|Enter}}.
+
We now need to mark some nav areas as the end of the map. For now, we will use the<code style="color:#E5E5E5; ">FINALE</code>attribute to temporarily mark the end of our campaign. Walk down to the second room in this level and select the occupying area with the {{key|Z}} key.
  
[[Image:l4d_nav_attribute_02.jpg|thumb|caption|left|400px|Marking a nav area with the PLAYER_START attribute.]]{{clr}}
+
{{clr}}
This will turn the selected area into a Player Start position for the survivors. It should turn a purple color.
+
[[Image:l4d_nav_attribute_04.jpg|thumb|caption|right|upright=1.2|The nav area is now marked with the FINALE attribute!]]
 +
<!--
 +
This only confuses people at the tutorial's current point; don't put this here
 +
{{note|Survival maps need both "Finale" and "Battlefield" attrributes on all areas.}}
 +
-->
 +
Bring down the console again, use<code style="color:#E5E5E5; background-color: #202020;">mark FINALE</code>on the marked area by pressing {{key|Enter}}. This will turn this room into a finale area, and its nav areas will turn blue.
  
{{tip|if you mark an area with an attribute and you want to remove it later, select the area and use "<code>clear_attribute <attribute name></code>" in the console to remove it. For example: <code>clear_attribute PLAYER_START</code>}}
+
{{clr}}
 +
[[Image:l4d_nav_attribute_05.jpg|thumb|caption|right|upright=1.2|Selecting the nav areas in the first room except the PLAYER_START area.]]
  
Left 4 Dead requires certain nav areas in its levels for the Director to work properly. For this simple test level, we will use another attribute called "FINALE".
+
Now the level has all it needs for the Director to work properly, and the Director can also now create a "flow" from the starting point to the destination point. However at the current state of the map, players will get mobbed by Common Infecteds right after jumping into the map, so let's mark<code style="color:#E5E5E5; ">EMPTY</code>attribute on areas around the PLAYER_START area. Reminder the select key is {{key|Z}}.
  
Walk down to the second room in this level and select the area that occupies by looking at it and pressing the {{key|Z}} key.
+
{{clr}}
 +
[[Image:l4d_nav_attribute_06.jpg|thumb|caption|right|upright=1.2|Marking the selected areas with the EMPTY attribute.]]
  
[[Image:l4d_nav_attribute_03.jpg|thumb|caption|left|400px|Selecting the nav area in the second room.]]{{clr}}
+
After picking the areas, apply the areas using<code style="color:#E5E5E5; background-color: #202020;">mark EMPTY</code>command. The areas now prevent new "wandering" Common Infecteds spawning on them, and look yellow.
  
Bring down the console and type "<code>mark FINALE</code>" and press {{key|Enter}}.
+
{{clr}}
 
+
Save the nav mesh using<code style="color:#E5E5E5; background-color: #202020;">nav_save</code>command, then reset / restart the map and see the new areas the Common Infecteds spawn at.
[[Image:l4d_nav_attribute_04.jpg|thumb|caption|left|400px|Marking the nav area with the FINALE attribute.]]{{clr}}
+
<hr>
 +
=== Attributes Addendum ===
 +
Navigation mesh attributes are abundant; you won't use them all, but eventually you may come accross certain situations where one attribute would just fit for it. Infact, there are actually two types of navigation mesh attributes, 'TERROR' Attributes and Base Attributes.
  
This will turn this room into a finale area and it will turn blue.
+
You can find out more at this [[List_of_L4D_Series_Nav_Mesh_Attributes|page]], and also a full list of navigation mesh attributes.
  
Now, the level has all it needs for the Director to work properly. The Director can create a "flow" from the starting point to the destination point.
+
===Infected Population===
 
+
The Population decides what Common and Uncommon infected roam your map. Useful for making your map feel more realistic, like a country side using rural infected, or placing Roadcrew uncommons on your map when a construction site is nearby.<br>
To make the level a little more playable, let's mark the areas around the Player Start area as "EMPTY" so that the player won't get mobbed right after jumping into the map.
+
See [[Left 4 Dead Infected Populations]] for detailed instruction on how to use existing populations, or making your very own.
 
 
Select all the areas around the Player Start with the {{key|Z}} key.
 
 
 
[[Image:l4d_nav_attribute_05.jpg|thumb|caption|left|400px|Selecting the nav areas in the first room except the PLAYER_START area.]]{{clr}}
 
 
 
Bring down the console and type "<code>mark EMPTY</code>" and press {{key|Enter}}.
 
 
 
[[Image:l4d_nav_attribute_06.jpg|thumb|caption|left|400px|Marking the selected areas with the EMPTY attribute.]]{{clr}}
 
 
 
This will prevent "wandering" common infected from appearing in these areas when the map starts.
 
 
 
{{note|It will not prevent mobs from spawning in these areas later. You will need to add the attribute "NO_MOBS" for that.}}
 
 
 
Save the nav mesh by using "<code>nav_save</code>".
 
  
 
=== Deleting nav areas ===
 
=== Deleting nav areas ===
Line 207: Line 208:
 
To connect 2 nav areas, select them and use "<code>nav_connect</code>" in the console. The {{key|End}} key is currently bound to this in the nav_mode.cfg file.
 
To connect 2 nav areas, select them and use "<code>nav_connect</code>" in the console. The {{key|End}} key is currently bound to this in the nav_mode.cfg file.
  
This will connect the areas in both directions and form a light blue line as seen in this image. Infected can climb up (they can climb to any area 180 units or lower) and they can drop down. Survivor bots can also drop down.
+
This will connect the areas in both directions and form a light blue line as seen in this image.<br>
 +
Common infected and the Witch can climb up to 180 units using this connection method. For higher distances use [[L4D_Level_Design/Versus_Maps#Making Infected Ladders Visible|Infected-only Ladders]].<br> Special infected and the Tank can not climb any distance up, they require Infected-only Ladders to climb up.<br> This is probably caused by the Special infected and Tank being playable characters which require ladders. All Infected and the player bots can jump down. Survivor bots may not jump down if the drop would cause in death.
  
 
To connect 2 areas one-way only, you will need to select the one you want to be able to connect to the other and then point to the second with the cursor but don't select it. Then, press {{key|End}} to use "<code>nav_connect</code>".
 
To connect 2 areas one-way only, you will need to select the one you want to be able to connect to the other and then point to the second with the cursor but don't select it. Then, press {{key|End}} to use "<code>nav_connect</code>".
Line 235: Line 237:
 
It is also possible to draw a ladder using <code>nav_begin_area</code> and <code>nav_end area</code>. Simply point at a corner of the ladder and move the cursor vertically to go to the opposite corner.
 
It is also possible to draw a ladder using <code>nav_begin_area</code> and <code>nav_end area</code>. Simply point at a corner of the ladder and move the cursor vertically to go to the opposite corner.
  
{{NavBar|:L4D Level Design/Visibility|L4D Level Design Basics Tutorial|L4D Level Design/Checkpoints}}
+
{{NavBar|L4D Level Design/Visibility|L4D Level Design Basics Tutorial|L4D Level Design/Checkpoints}}
 
 
 
[[Category:Left 4 Dead]]
 
[[Category:Left 4 Dead]]
 
[[Category:Left 4 Dead 2]]
 
[[Category:Left 4 Dead 2]]
 
[[Category:Level Design]]
 
[[Category:Level Design]]

Latest revision as of 06:50, 22 July 2021

Français Português-Brasileiro 简体中文

Next we'll create a Navigation Mesh, or "Nav Mesh", for our level. The Nav Mesh represents the "walkable areas" of a map. This allows the Survivor Bots and Infected to "know" how to move around in the environment, and tells the AI 'director' where it can spawn infected.

Create tutorial04.vmf and compile

In Hammer, open the map file tutorial03.vmf that you created in the previous tutorial (if it's not already open). This should be located in the tutorial mapsrc folder, by default:

C:\Program Files\Steam\steamapps\common\left 4 dead\sdk_content\mapsrc\

Now we'll make a new version to work with and compile it:

  • Go to File menu and choose Save As...
  • Change the name to tutorial04.vmf.
  • Press F9 to open the Run Map dialog and click on the OK button to compile it.

Getting Started

When the level loads:

  1. As before, we'll get a "Map is unplayable" dialog because we don't yet have a Nav Mesh. Press Continue to dismiss the dialog.
  2. Bring down your developer console ` (tilde)
  3. Type "director_stop" and press the Enter key.
    This will stop the AI Director from spawning Infected.
  4. Enter the command "nb_delete_all" and press Enter.
    This will remove any Infected and Survivor bots from the current game.
  5. Enter the command "nav_edit 1" and press Enter.
    This will switch the game to Nav Mesh editing mode.
  6. Hide the console again with `.

Generating a new Nav Mesh

Placing a nav_mark_walkable.

With the console closed, look at the floor in the middle of the hallway between the two rooms.

Bring down the console and type "nav_mark_walkable" and press Enter.

Close the console and you should see a pyramid-like shape on the ground where you are pointing.

You have just placed a nav generation marker called a "nav_mark_walkable".

The nav areas automatically generated.

Bring down your console again and type "nav_generate_incremental" and press Enter.

This will generate a set of nav areas around the nav_mark_walkable marker. Nav mesh areas appear as series of connected square blocks. It should generate throughout your entire two room level.

Note.png Note: If you have a bigger level, you will need to place more of the nav_mark_walkable markers throughout your level. Each nav_mark_walkable has a radius that it creates areas around. In general, build nav areas for one section at a time to keep the nav mesh clean.
Tip.png Tip: The nav_generate_incremental automatically saves the Nav Mesh into you map when it is run. If you want to save your progress manually, use can use the "nav_save" command.

Nav Area selection

After a nav_generate_incremental is run, all of the new nav areas it creates stay selected. This comes in handy if you make a mistake and want to run the generation again. To delete the selected nav, enter the command "nav_delete" into the console and it will delete all nav areas that are selected. If you try this, you can recreate the nav areas by simply dropping another nav_mark_walkable marker and running nav_generate_incremental again.

  • To deselect nav, type "nav_clear_selected_set".
  • To select a nav area, look at the area with your cursor and type "nav_toggle_in_selected_set". This will select the nav area you are pointing at.

Nav Config files

As you can tell, editing the Nav Mesh uses a lot of console commands. The most effective way to edit, instead of typing a console command each time, is to bind keys to these commands to use as shortcuts.

A config (.cfg) file has been included that makes it easier to start with.

Bring down your console and type:

bind PGDN "exec nav_mode"

and press Enter.

Now pressing the Page Down key will toggle between "Nav Edit" mode and "Game" mode.

Binding your own keys (advanced)

To set your own keys using the bind command, bring down your console and type:

bind <key> "console command"

For example, if you want to bind the Z key to "nav_toggle_in_selected_set", type this in your console:

bind z "nav_toggle_in_selected_set"

You may want to open the left4dead/cfg/nav_mode.cfg file in a text editor to add or change key bindings.

  • For more information on binding commands to keys, see Bind.
Note.png Note: From now on, this tutorial will assume you are using the default nav_mode.cfg. If you're using your own bindings, you'll have to substitute your own key shortcuts for the one given.

Splitting Nav Areas

The Navigation Mesh in your level currently may have large areas that cover the entire room. Sometimes it's necessary to split those large areas into smaller ones. For example, adding an attribute at where the survivors start, but you only want it at the area in front of the weapons table.

You can split up nav areas by using "nav_split".

The white line previews the split that you can make.

In the included nav_mode.cfg file, nav_split is bound to the Insert key.

As you point at the nav areas, you will see a white line that moves either North/South or East/West with your cursor. Position the cursor so that a line draws to the right of the weapon table in the first room you created.

This line shows where the split will happen if you use nav_split.

Performing a nav_split.

Then, press Insert to perform the split.

Splitting the nav area in the other direction.

Now, position the cursor so that the new area you just split in front of the weapon table is split in half in the other direction.

Press Insert again to perform a second split and see the result.

Adding Attributes

Nav areas may be marked with attributes that designate specific purposes, some being essential. For example, theEMPTYdisallows common infecteds to spawn on it, and lets them not spawn on weird areas, like a kitchen counter. In our navigation mesh, we need to mark an essential attribute, thePLAYER_STARTattribute, which designates where the Survivors should start for the campaign's first map. Let's mark the area in front of the weapon table that we just split with the attribute.

Selecting a nav area with nav_toggle_in_selected_set.

Start by visualing the attributes using thez_debug 1console command, then point your cursor at the area and usenav_toggle_in_selected_setby pressing the Z key.

A nav area marked with the PLAYER_START attribute!

After selecting the area, usemark PLAYER_STARTby pressing Enter after typing it. The selected area will then turn purple, meaning now Survivors start on this nav area at the start of the campaign.

Tip.png Tip: To remove attributes, select the area and useclear_attribute [attribute's name here]in the console with the respective attribute name. You can also remove all attributes in a map by not selecting any nav areas when using the command.
In the second room, and selecting its navigation area.

We now need to mark some nav areas as the end of the map. For now, we will use theFINALEattribute to temporarily mark the end of our campaign. Walk down to the second room in this level and select the occupying area with the Z key.

The nav area is now marked with the FINALE attribute!

Bring down the console again, usemark FINALEon the marked area by pressing Enter. This will turn this room into a finale area, and its nav areas will turn blue.

Selecting the nav areas in the first room except the PLAYER_START area.

Now the level has all it needs for the Director to work properly, and the Director can also now create a "flow" from the starting point to the destination point. However at the current state of the map, players will get mobbed by Common Infecteds right after jumping into the map, so let's markEMPTYattribute on areas around the PLAYER_START area. Reminder the select key is Z.

Marking the selected areas with the EMPTY attribute.

After picking the areas, apply the areas usingmark EMPTYcommand. The areas now prevent new "wandering" Common Infecteds spawning on them, and look yellow.

Save the nav mesh usingnav_savecommand, then reset / restart the map and see the new areas the Common Infecteds spawn at.


Attributes Addendum

Navigation mesh attributes are abundant; you won't use them all, but eventually you may come accross certain situations where one attribute would just fit for it. Infact, there are actually two types of navigation mesh attributes, 'TERROR' Attributes and Base Attributes.

You can find out more at this page, and also a full list of navigation mesh attributes.

Infected Population

The Population decides what Common and Uncommon infected roam your map. Useful for making your map feel more realistic, like a country side using rural infected, or placing Roadcrew uncommons on your map when a construction site is nearby.
See Left 4 Dead Infected Populations for detailed instruction on how to use existing populations, or making your very own.

Deleting nav areas

If you make a mistake or if you find that the auto generation of the nav mesh has mistakes, you can delete nav areas with the command "nav_delete". For example, the weapons table doesn't actually need a nav area on top of it. It may cause survivors to jump up onto it, which might not be desirable.

In the config file provided, this command is already bound to the Delete key.

To delete a nav area, point at it, select it with the Z key. Make sure you only have the areas you want to delete selected, then press Delete.

Analyzing the Nav

Your first nav mesh in the game.

Now that we have a basic nav mesh, we need the game to analyze it so that the director knows where it can spawn infected.

Bring down the console and type "nav_analyze" and press Enter.

This might take a few seconds and then the level will reload.

To test spawning infected, use "director_start" in the console and reload the level with "map tutorial04".

Your scene should look something like this now.

Adding Nav to a Ladder

If you open up tutorial03 in the game, and switch to nav_edit 1, you'll see how a ladder looks with nav placed on it.

Creating nav on a ladder.

To create nav on a func_ladder, position your cursor over it in nav_edit mode and use "nav_build_ladder".

Note.png Note: The cursor will turn a green color if it is positioned over a func_ladder.

Connecting Nav Areas

While a lot of the nav areas will be connected properly when you use nav_generate_incremental, there are some that you might want to tweak or change. For example, the catwalk we created in tutorial03 might not have connected properly to the areas below it.

Connecting nav areas.

To connect 2 nav areas, select them and use "nav_connect" in the console. The End key is currently bound to this in the nav_mode.cfg file.

This will connect the areas in both directions and form a light blue line as seen in this image.
Common infected and the Witch can climb up to 180 units using this connection method. For higher distances use Infected-only Ladders.
Special infected and the Tank can not climb any distance up, they require Infected-only Ladders to climb up.
This is probably caused by the Special infected and Tank being playable characters which require ladders. All Infected and the player bots can jump down. Survivor bots may not jump down if the drop would cause in death.

To connect 2 areas one-way only, you will need to select the one you want to be able to connect to the other and then point to the second with the cursor but don't select it. Then, press End to use "nav_connect".

Make sure in both cases that the two areas you want to connect are not layered on top of one another. This will cause infected to bump their heads when they try to climb up.

Drawing your own Nav areas

Sometimes the nav_generate_incremental leaves out areas that you want to have nav on. In these cases, you will need to draw your own nav area.

Drawing nav areas is done with 2 keys. One key is bound to "nav_begin_area" and other bound to "nav_end_area". The nav.cfg file has nav_begin_area bound to the left mouse button and "nav_end_area" bound to the right mouse button.

Point to the area you want to create an area and click the left mouse button. As you move the mouse around, you can see where the nav area will draw until you press the right mouse button to end drawing and create the area.

Drawing a nav area.

Click the right mouse to activate nav_end_area and see the result.

Note.png Note: Creating your own nav areas will not automatically connect them to the rest of the nav mesh. Use nav_connect to connect them to adjacent areas.
Tip.png Tip: If you accidentally press the left mouse button when you don't want to draw a nav area, just press the left mouse button again and it will cancel the nav creation.

Grid snapping when drawing nav

You might notice that the cursor doesn't snap to a grid when you're in this mode. You can set the snapping properties using "nav_snap_to_grid" in the console.

Tip.png Tip: In the nav.cfg, the F9 key is bound to "incrementvar nav_snap_to_grid 0 2 1". This will change the grid size when you press the bound key and continue to toggle through the sizes each time you press the F9 key.

It is also possible to draw a ladder using nav_begin_area and nav_end area. Simply point at a corner of the ladder and move the cursor vertically to go to the opposite corner.