![Page 1: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/1.jpg)
NavMeshesCMSC425.01 Fall 2019
![Page 2: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/2.jpg)
Today’s question
How NPCs move around:NavMeshes
![Page 3: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/3.jpg)
Navigation problems• Navigating from place to place• Dense crowd navigation• Coordinated team movement• Pursuit• Moving complex/articulated shape
• Piano movers problem(rigid)• Skeleton (articulated)
![Page 4: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/4.jpg)
@UMD: Dinesh and Ming
• Dense crowd simulations• How to move many agents
naturally
• Video
![Page 5: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/5.jpg)
Navigation Version 1: Use a mapCreate graph structureUse Dijkstra's algorithm
Shortest path
Assumption: World is rigid, limited lanes for movement
![Page 6: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/6.jpg)
What is "shortest" path?
• Distance?
![Page 7: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/7.jpg)
What is "shortest" path?
• Distance?• Speed?• Energy cost?• Exposure to enemy?
• Hex map• 6 directions• Terrain types => speed costs
![Page 8: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/8.jpg)
Navigation Version 2: Open Terrain
• Mix of obstacles and open spaces: "free space geometry"• More options for direction• How pick path?
![Page 9: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/9.jpg)
How pick best path?
• Shortest may not be most natural (dashed line)• Need way to detect natural
corridors
![Page 10: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/10.jpg)
Solution 1: Waypoint roadmap
• Preprocess space into graph of waypoints• Place waypoints along natural
corridors
![Page 11: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/11.jpg)
Solution 1: Waypoint roadmap
• Preprocess space into graph of waypoints• Place waypoints along natural
corridors• Drawbacks• Could need lots of way points• Harder to plan for coordinated
team movement
![Page 12: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/12.jpg)
Solution 2: Navmesh
• Preprocess space into mesh of free areas as polygons• Plan movement between
polygons• Between edges• Between centers
• Multiple level graph search• First between regions• Then pick entry and exit points
![Page 13: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/13.jpg)
Navmeshes can be
• Labeled with different terrain types• Set with "gates"
• 2D manifolds which are topologically complex (eg, non-planar)
![Page 14: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/14.jpg)
Using Navmesh
• Inside region use direct path
• Regions (and subregions) can be labeled with different terrain types and costs
![Page 15: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/15.jpg)
Creating Navmeshes from terrain
• Step 1: Find walkable surfaces• As large polygon "map"
• Step 2: Simplify boundaries• Simplify polygon "map"
• Step 3: Triangulate "map"• Cover with set of triangles
![Page 16: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/16.jpg)
Creating Navmeshes from terrain
• Step 1: Find walkable surfaces based on agent height, width, slope ability
• Variation on piano movers problem
(a) (b)
h
too shortok
too steep
![Page 17: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/17.jpg)
Creating Navmeshes from terrain
• Step 2: Simplify boundaries• Simplify polygon "map"
• Recursive refinement of straight line
![Page 18: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/18.jpg)
Creating Navmeshes from terrain
• Step 3: Triangulate "map"• Cover with set of triangles
• Bridge holes• Cut ears (!)
(a) (b)
v0
v1v2
vi�1
vi+1
viear
(c)
vn
chord
chordbridging
![Page 19: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/19.jpg)
Use Navmesh: find path
• Discretize by adding points• Find shortest path
(b) (c)(a)
![Page 20: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/20.jpg)
Use Navmesh: refine
• Smooth and clean path
(a) (b) (c)
t
s
t
s
t
s
![Page 21: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/21.jpg)
Navmeshes in Unity
• Create terrain• Terrain editor
• Set agent navigation properties• Height, width of agent• Slope capability
• Bake Navmesh• Finds navigable regions• Creates mesh
![Page 22: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/22.jpg)
Agent properties
• Radius, Height• Step height• Max slope
• Can have multiple agent types
![Page 23: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/23.jpg)
Off mesh links
![Page 24: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/24.jpg)
Question
• How does this all relate to colliders?
![Page 25: NavMeshes - cs.umd.edu · •Variation on piano movers problem (a) (b) h ok too short too steep. Creating Navmeshesfrom terrain •Step 2: Simplify boundaries •Simplify polygon](https://reader034.vdocuments.net/reader034/viewer/2022050421/5f90cd62a045237b722a9ed3/html5/thumbnails/25.jpg)
Readings
• Look at Unity manual and tutorials• Terrain• https://docs.unity3d.com/Manual/terrain-UsingTerrains.html
• NavMesh• https://unity3d.com/learn/tutorials/topics/navigation/navmesh-agent• https://docs.unity3d.com/Manual/nav-BuildingNavMesh.html
• Animation• https://unity3d.com/learn/tutorials/topics/animation/animate-anything-
mecanim• https://unity3d.com/learn/tutorials/s/animation