Nav Mesh: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (Clarify what?)
 
(143 intermediate revisions by 46 users not shown)
Line 1: Line 1:
[[Category:Level Design]]
{{LanguageBar}}


==Introduction==
A [[w:Navigation mesh|'''Navigation Mesh''']] ('''NavMesh''' or '''nav mesh''') is a data structure that stores data used for path finding, which is typically used by bots. In {{source|4}}, navigation meshes are used by the following entities:
A ''Navigation Mesh'' represents the "walkable areas" of a map. This data is '''required''' by Bots and Hostages in Counter-Strike:Source, allowing them to "know" how to move around in the environment.
# [[Bot]]s and Hostages in:
#* {{css|4}}
#* {{csgo|4}}
# [[NextBot]] entities in:
#* {{l4d|4}}
#* {{l4d2|4}}
#* {{gmod|4}}
#* {{tf2|4}}
#* {{p3|4}}
#* {{jb3|4}}
#* {{bms|4}}
…to realize what's navigable in their environment, and path to their desired destination.


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 <code>cstrike\maps\de_dust.bsp</code> is stored in <code>cstrike\maps\de_dust.nav</code>.
==NAV file format==
{{Main|.nav}}


==Automatic Navigation Mesh Generation==
==NAV files ==
To support the many community-created maps, Counter-Strike:Source includes an automatic mesh generation system. The first time you attempt to play a custom map with bots, the generation system will build a .nav file for that map.  Depending on the size and complexity of the map, this may take a few minutes to a few hours.  Most maps take about 5 minutes to auto-generate a .nav file.  Once the generation is complete, a .nav file is saved to your hard drive for future use.
Navigation Mesh data is stored in a [[NAV]] file corresponding to the map file ([[BSP|.bsp]]) for which it is used. For example, the nav mesh for <code>cstrike\maps\de_dust[[.bsp]]</code> is stored in <code>cstrike\maps\de_dust[[.nav]]</code>.


===What is Computed During Generation===
==Navigation Mesh Editing==
The following steps occur during Navigation Mesh generation:
{{Main|Nav Mesh Editing}}
* Starting at a player spawn point, walkable space is sampled by "flood-filling" outwards from that spot, searching for adjacent walkable points
{{Main|Nav Mesh Commands}}
* Rectangular ''Navigation Areas'' are constructed from the sampled data
The Navigation Mesh Editing is done in-game. A (new) .nav file can be generated with <code>nav_generate</code> (which requires {{Command|sv_cheats|1}} and {{Command|nav_edit|1}}).
* Hiding and Sniper spots are computed
* Encounter Spots and Approach Points are computed (this can take awhile)
* Initial Encounter areas are computed


===Manually Starting the Generation Process===
==Game Specific SubVersions==
To start the generation process manually, type <code>nav_generate</code> from the console.
{| class="standard-table"
! Game !! Nav Mesh Class !! Subversion !! Notes
|-
| {{source|2}}
{{gmod|2}}
| TheNavMesh
| 0
| Garry's Mod uses the base navigation mesh (It doesn't use its own implementation unlike Valve games)
|-
| {{css|2}}
{{csgo|2}}
| CSNavMesh
| 1
| * Appends approach area data to each area.
|-
| {{tf2|2}}
| CTFNavMesh
| 2
| Appends TF2-specific attribute flag to area data.
|-
| {{l4d|2}}
| TerrorNavMesh
| 13
|
|-
| {{l4d2|2}}
| TerrorNavMesh
| 14
|}


===Viewing the Navigation Mesh===
==See also==
To see the resulting Navigation Mesh, type <code>nav_edit 1</code>.  To turn the mesh editor off, type <code>nav_edit 0</code>.
* [[Nav Mesh Commands|Navigation Mesh Console Command Reference]]
* [[List of L4D Series Nav Mesh Attributes]]
* [[L4D Level Design/Nav Meshes]]
* [[L4D Level Design/Nav Flow]]
* [[L4D Level Design/Advanced Nav Editing]]


===Explicity Marking Walkable Areas (ie: "There's no mesh upstairs")===
==External links==
Some maps that have very steep stairs, ramps, or hills may confuse the generation system, resulting in the Navigation Mesh not covering the entire map. To solve this, you can manually place additional ''walkable markers'' that tell the generator to search outwards from that point during its sampling phase.
* Official forums for the bot system (down) - [http://web.archive.org/web/*/http://www.turtlerockstudios.com/forums/csbot/ Archived version].
* [https://www.editlife.net/tutorial.php?tutid=60 Waypointing for CS:S Bots/Hostages (Edit Life)]


To add one or more walkable markers, first aim your view towards a known walkable spot in your map, then type <code>nav_mark_walkable</code> in the console.  When you are finished placing markers, type <code>nav_generate</code> to re-generate the mesh.
[[Category:Source]]


===Quickly Generating Meshes for Testing===
[[Category:Level Design]]<!--Why?-->
The analysis phase of the generator can be quite time consuming.  To skip it, type <code>nav_quicksave 1</code> in the console. 
<blockquote>'''NOTE:''' "Quicksaving" skips the analysis phase, and the resultant nav mesh will be missing important data required by the CS Bots and Hostages higher-level planning and attention systems.  While useful for testing, editing, and tuning a nav mesh, be sure to do a full analyze (ie: with <code>nav_quicksave 0</code>) before publishing your nav file to others.</blockquote>
 
==Editing the Navigation Mesh==
The automated Navigation Mesh generator does a reasonable job of constructing a mesh, allowing you to start using Bots and Hostages on custom maps easily.
 
However, careful hand-tuning of the Navigation Mesh can markedly improve the performance of Bots.  In addition, manually decorating the mesh with ''Place Names'' allows the Bots to tell others where events occur, enhances the Counter-Strike radar and includes Place Names in all radio messages.
 
[[Image:nav_edit.jpg|frame|400px|Enabling the Navigation Mesh editor in de_dust]]
===The Navigation Mesh Editor===
 
To enable the editor, type <code>nav_edit 1</code> in the console (type <code>nav_edit 0</code> to disable it).
 
* The white cross in the center of your view is the ''cursor''.
* The Navigation Area you are pointing at is the ''selected area'' and is shown with a yellow outline.
* Navigation Areas that can be reached from the selected area are shown in red.
* The white line in the selected area denotes where the area will be split if the <code>nav_split</code> command is executed.
 
===Using Mesh Editing Commands===
Although all of the mesh editing commands can be typed in the console, in practise it is far easier to ''bind'' these commands to keys.  For example, <code>bind del nav_delete</code> binds the delete key to the command nav_delete.  After this binding, pressing the delete key will delete the nav area under your cursor (if you are nav editing mode).
 
===Basic Mesh Editing Commands===
====Split====
To split an area into two adjacent, inter-connected areas, aim your cursor at an area and execute the <code>nav_split</code> command.
[[Image:nav_edit.jpg|400px|Before split]]
[[Image:nav_split.jpg|400px|After split]]
 
====Merge====
To merge two adjacent areas:
# Aim your cursor at the first area and execute <code>nav_mark</code>
# Aim your cursor at the second area and execute <code>nav_merge</code>
 
Note that both areas must be the same size along the edge to be merged.
 
[[Image:nav_mark.jpg|300px|Marked first area]]
[[Image:nav_pre_merge.jpg|300px|Aim at second area]]
[[Image:nav_post_merge.jpg|300px|Merged]]
 
The resulting area will retain all of the connections of the original two areas, and inherit properties (ie: Place Names, etc) from the marked area.
 
====Splice====
Splicing creates a new area between two existing areas.
 
[[Image:nav_prep_splice.jpg|300px|Marked first area]]
[[Image:nav_pre_splice.jpg|300px|Aim at second area]]
[[Image:nav_post_splice.jpg|300px|New area spliced between]]
 
====Delete====
To delete an area, aim your cursor at it and execute <code>nav_delete</code>
 
====Creating a New Area====
To manually create a new area:
# Place your cursor at where a corner of the new area should be
# Execute <code>nav_begin_area</code>
# Move your cursor to drag out the area's extent
# Execute <code>nav_end_area</code>
 
[[Image:nav_begin_area.jpg|300px|Start dragging area at first corner]]
[[Image:nav_drag_area.jpg|300px|Drag area extent]]
[[Image:nav_end_area.jpg|300px|Area created]]
 
 
====Adding and Removing Connections Between Areas====
The connections between areas define whether an agent can move from one area to another. Usually these connections are ''bidirectional'', meaning agents can move back and forth between two areas at will.  However, sometimes the connection is ''one way'', as in the case of high ledges that can be jumped down, but not back up.
 
To make a one-way connection from area A to area B (meaning you can move from A to B):
# Place your cursor on area A
# Mark area A with <code>nav_mark</code>
# Aim your cursor at area B
# Execute <code>nav_connect</code>
 
To make a bidirectional connection, repeat the above steps reversing the roles of A and B.
 
To remove all connections from areas A and B:
# Aim at area A
# Mark area A with <code>nav_mark</code>
# Aim at area B
# Execute <code>nav_disconnect</code>
 
===Advanced Editing Techniques===
 
====Ladders====
Editing ladders in the nav mesh.
 
====Preventing Excessive Jumping====
When to use the <code>nav_no_jump</code> flag.
 
====Obstacle Avoidance and Precision Movement====
Using <code>nav_precise</code>, <code>nav_walk</code>, and <code>nav_stop</code> to disable local obstacle avoidance behaviors and control bot movement.
 
====Marking Areas to Avoid====
Using <code>nav_avoid</code> to tell bots to avoid the area unless the normal route has become too dangerous.
 
====Controlling Where Bots Can Hide====
Using <code>nav_no_hide</code> to prevent bots from hiding in that area.
How to force the creation of hiding spots during the analysis phase.
 
====Dealing with Rotating Doors====
Carving out empty space in the nav mesh to allow for the rotating door.
 
====Lining up Tricky Jumps and Narrow Doorways====
Arranging nav areas to force specific paths.
 
==Navigation Mesh Console Command Reference==
===Commands===
nav_check_file_consistency<br/>
Scans the maps directory and reports any missing/out-of-date navigation files.
 
nav_update_blocked<br/>
Updates the blocked/unblocked status for every nav area.
 
nav_check_floor<br/>
Updates the blocked/unblocked status for every nav area.
 
nav_remove_unused_jump_areas<br/>
Removes jump areas with at most 1 connection to a ladder or non-jump area.
 
nav_delete<br/>
Deletes the currently highlighted Area.
 
nav_split<br/>
To split an Area into two, align the split line using your cursor and invoke the split command.
 
nav_make_sniper_spots<br/>
Chops the marked area into disconnected sub-areas suitable for sniper spots.
 
nav_merge<br/>
To merge two Areas into one, mark the first Area, highlight the second by pointing your cursor at it, and invoke the merge command.
 
nav_mark
Marks the Area or Ladder under the cursor for manipulation by subsequent editing commands.
 
nav_unmark
Clears the marked Area or Ladder.
 
nav_begin_area
Defines a corner of a new Area or Ladder. To complete the Area or Ladder, drag the opposite corner to the desired location and issue a 'nav_end_area' command.
 
nav_end_area
Defines the second corner of a new Area or Ladder and creates it.
 
nav_connect
To connect two Areas, mark the first Area, highlight the second Area, then invoke the connect command. Note that this creates a ''one-way'' connection from the first to the second Area. To make a two-way connection, also connect the second area to the first.
 
nav_disconnect
To disconnect two Areas, mark an Area, highlight a second Area, then invoke the disconnect command. This will remove all connections between the two Areas.
 
nav_splice
To splice, mark an area, highlight a second area, then invoke the splice command to create a new, connected area between them.
 
nav_crouch
Toggles the 'must crouch in this area' flag used by the AI system.
 
nav_precise
Toggles the 'dont avoid obstacles' flag used by the AI system.
 
nav_jump
Toggles the 'traverse this area by jumping' flag used by the AI system.
 
nav_no_jump
Toggles the 'dont jump in this area' flag used by the AI system.
 
nav_stop
Toggles the 'must stop when entering this area' flag used by the AI system.
 
nav_walk
Toggles the 'traverse this area by walking' flag used by the AI system.
 
nav_run
Toggles the 'traverse this area by running' flag used by the AI system.
 
nav_avoid
Toggles the 'avoid this area when possible' flag used by the AI system.
 
nav_transient
Toggles the 'area is transient and may become blocked' flag used by the AI system.
 
nav_dont_hide
Toggles the 'area is not suitable for hiding spots' flag used by the AI system.
 
nav_stand
Toggles the 'stand while hiding' flag used by the AI system.
 
nav_no_hostages
Toggles the 'hostages cannot use this area' flag used by the AI system.
 
nav_strip
Strips all Hiding Spots, Approach Points, and Encounter Spots from all Areas in the mesh.
 
nav_save
Saves the current Navigation Mesh to disk.
 
nav_load
Loads the Navigation Mesh for the current map.
 
nav_use_place
If used without arguments, all available Places will be listed. If a Place argument is given, the current Place is set.
 
nav_place_replace
Replaces all instances of the first place with the second place.
 
nav_place_list
Lists all place names used in the map.
 
nav_toggle_place_mode
Toggle the editor into and out of Place mode. Place mode allows labelling of Area with Place names.
 
nav_set_place_mode
Sets the editor into or out of Place mode. Place mode allows labelling of Area with Place names.
 
nav_place_floodfill
Sets the Place of the Area under the cursor to the curent Place, and 'flood-fills' the Place to all adjacent Areas. Flood-filling stops when it hits an Area with the same Place, or a different Place than that of the initial Area.
 
nav_place_pick
Sets the current Place to the Place of the Area under the cursor.
 
nav_toggle_place_painting
Toggles Place Painting mode. When Place Painting, pointing at an Area will 'paint' it with the current Place.
 
nav_mark_unnamed
Mark an Area with no Place name. Useful for finding stray areas missed when Place Painting.
 
nav_corner_select
Select a corner of the currently marked Area. Use multiple times to access all four corners.
 
nav_corner_raise
Raise the selected corner of the currently marked Area.
 
nav_corner_lower
Lower the selected corner of the currently marked Area.
 
nav_corner_place_on_ground
Places the selected corner of the currently marked Area on the ground.
 
"nav_warp_to_mark"
game cheat
- Warps the player to the marked area.
"nav_ladder_flip"
game cheat
- Flips the selected ladder's direction.
"nav_generate"
game cheat
- Generate a Navigation Mesh for the current map and save it to disk.
"nav_generate_incremental"
game cheat
- Generate a Navigation Mesh for the current map and save it to disk.
"nav_analyze"
game cheat
- Re-analyze the current Navigation Mesh and save it to disk.
"nav_mark_walkable"
game cheat
- Mark the current location as a walkable position. These positions are used as seed locations when sampling the map to generate a
 
Navigation Mesh.
"nav_clear_walkable_marks"
game cheat
- Erase any previously placed walkable positions.
"nav_compress_id"
game cheat
- Re-orders area and ladder ID's so they are continuous.
"nav_show_ladder_bounds"
game cheat
- Draws the bounding boxes of all func_ladders in the map.
"nav_build_ladder"
game cheat
- Attempts to build a nav ladder on the climbable surface under the cursor.
 
 
===Console Variables===
nav_coplanar_slope_limit ''value''<br/>
 
nav_split_place_on_ground ''(0 or 1)'' <br/>
If set to 1, nav areas will be placed flush with the ground when split.
 
nav_area_bgcolor ''R G B A''<br/>
RGBA color to draw as the background color for nav areas while editing.
 
nav_show_area_info ''duration''<br/>
Duration in seconds to show nav area ID and attributes while editing
 
nav_snap_to_grid ''(0 or 1)''<br/>
If set to 1, snap to the nav generation grid when creating new nav areas
 
nav_create_place_on_ground ''(0 or 1)''<br/>
If set to 1, nav areas will be placed flush with the ground when created by hand.
 
nav_draw_limit ''count''<br/>
The maximum number of areas to draw in edit mode
 
nav_slope_limit ''Z''<br/>
The ground unit normal's Z component must be greater than this for nav areas to be generated.
 
nav_restart_after_analysis ''(0 or 1)''<br/>
If set to 1, when nav nav_restart_after_analysis finishes, restart the server.  Turning this off can cause crashes, but is useful for incremental generation.
 
nav_edit ''(0 or 1)''<br/>
Set to one to interactively edit the Navigation Mesh. Set to zero to leave edit mode.
 
nav_quicksave ''(0 or 1)''<br/>
Set to one to skip the time consuming phases of the analysis.  Useful for data collection and testing.
 
nav_show_approach_points ''(0 or 1)''<br/>
Show Approach Points in the Navigation Mesh.
 
nav_show_danger ''(0 or 1)''<br/>
Show current 'danger' levels.
 
nav_show_player_counts ''(0 or 1)''<br/>
Show current player counts in each area.
 
 
----
 
Addition information can be found [http://www.turtlerockstudios.com/forums/csbot/viewtopic.php?t=725 here].

Latest revision as of 00:14, 8 July 2025

English (en)Deutsch (de)Esperanto (eo)Español (es)日本語 (ja)中文 (zh)Translate (Translate)

A Navigation Mesh (NavMesh or nav mesh) is a data structure that stores data used for path finding, which is typically used by bots. In Source Source, navigation meshes are used by the following entities:

  1. Bots and Hostages in:
  2. NextBot entities in:

…to realize what's navigable in their environment, and path to their desired destination.

NAV file format

Main article:  .nav

NAV files

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.

Navigation Mesh Editing

Main article:  Nav Mesh Editing
Main article:  Nav Mesh Commands

The Navigation Mesh Editing is done in-game. A (new) .nav file can be generated with nav_generate (which requires sv_cheats 1 and nav_edit 1).

Game Specific SubVersions

Game Nav Mesh Class Subversion Notes
Source Source

Garry's Mod Garry's Mod

TheNavMesh 0 Garry's Mod uses the base navigation mesh (It doesn't use its own implementation unlike Valve games)
Counter-Strike: Source Counter-Strike: Source

Counter-Strike: Global Offensive Counter-Strike: Global Offensive

CSNavMesh 1 * Appends approach area data to each area.
Team Fortress 2 Team Fortress 2 CTFNavMesh 2 Appends TF2-specific attribute flag to area data.
Left 4 Dead Left 4 Dead TerrorNavMesh 13
Left 4 Dead 2 Left 4 Dead 2 TerrorNavMesh 14

See also

External links