finding a path
play

Finding a Path Often seems obvious and natural in real life - PDF document

3/21/2016 Finding a Path Often seems obvious and natural in real life Advanced Pathfinding e.g., Get from point A to B go around lake http://www.rocket5studios.com/tutorials/make-a-2d-game-with-


  1. 3/21/2016 Finding a Path • Often seems obvious and natural in real life Advanced Pathfinding – e.g., Get from point A to B � go around lake http://www.rocket5studios.com/tutorials/make-a-2d-game-with- unity3d-using-only-free-tools-beginning-enemy-ai-with-a-pathfinding/ • For computer controlled player, may be difficult IMGD 4000 – e.g., Going from A to B goes through enemy base! • Want to pick “best” path With material from: Millington and Funge, Artificial Intelligence for Games , Morgan Kaufmann 2009 (Chapter 4) and Buckland, Programming • Need to do it in real-time Game AI by Example , Wordware 2005 (Chapter 5, 8). http://www.codeofhonor.com/blog/the-starcraft-path-finding-hack Finding a Path A* Pathfinding Search • Path – a list of cells, points or • Covered in detail in IMGD 3000 nodes that agent must traverse to get to from start http://web.cs.wpi.edu/~imgd4000/d16/slides/imgd3000-astar.pdf to goal • Basic A* is a minimal requirement for solo – Some paths are better than others project � measure of quality – You may use any reference code as a guide, but • A* is commonly used not copy and paste (cf. academic honesty policies) heuristic search • An advanced pathfinding feature will be – Complete algorithm in that if there is path, will find http://www.cognaxon.com/index.php?page=educational optional, but required for an A – Using “distance” as heuristic measure, then guaranteed – This slide deck optimal 4 Tile-Based Practical Path Planning Navigation Graphs • Sometimes, basic A* is not enough Common, especially if environment • already designed in squares or • Also, often need: hexagons – Navigation graphs Node center of cell; edges to • • Points of visibility (pov) – lines connecting visible nodes adjacent cells • Navigation mesh (navmesh) – models traversable areas of Each cell already labeled with • virtual map http://opinionatedgamers.com/2011/12/07/review-of-kingdom-builder/ material (mud, river, etc.) – Path smoothing Downside: • – Compute-time optimizations – Can burden CPU and memory – Hierarchical pathfinding e.g., Modest 100x100 cell map has • 10,000 nodes and 78,000 edges! – Special case methods – Especially if multiple AI’s calling at • Some of these count as optional requirement same time Most of slide deck is survey about how to do better... 5 6 http://forum.cocos2d-objc.org/t/tilemapkit-complete-tiled-tmx-tilemap-support-including-hex-staggered-iso/17313 1

  2. 3/21/2016 Outline Point of Visibility (POV) Navigation Graph • Introduction (done) • Navigation Graphs (next) • Navigation Mesh • Pathfinding Tuning • Pathfinding in UE4 • Place graph nodes (usually by hand) at important points in environment • Such that each node has line of sight to at least one other node 8 POV Navigation Blind Spots in POV Find closest visible node (a) to current location • Find closest visible node (b) to target location • • No POV point is visible from red spots! Search for least cost path from (a) to (b), e.g. A* • • Easy to fix manually in small graphs Move to (a) • Follow path to (b) • • A problem in larger graphs Move to target location Note, some “backtracking” • DEMO (COARSE) DEMO (COARSE) 9 10 Automatic POV by Expanded Geometry POV Navigation • Advantage (A) Expand geometry – Obvious how to build and expand By amount proportional – to bounding radius of • Disadvantages moving agents – Can have “blind spots” (B) Connect all vertices – Can have “jerky” (backtracking) paths (C) Prune non-line of sight – Can take a lot of developer time, especially if design is rapidly evolving points – Problematic for random or user generated maps � Avoids objects hitting • Solutions edges when pathing 1. Automatically generate POV graphs 2. Make finer grained graphs Note: works best if bounding 3. Path smoothing radius similar for all units 11 12 2

  3. 3/21/2016 Flood Fill to Produce Finely Grained Graph Finely Grained Graphs Place “seed” in graph • Expand outward • – e.g., 8 directions – Making sure nodes and edges passable by bounding radius Continue until covered • � Produces a finely grained graph Upside? Improves blind spots and path smoothness • Note, same algorithm • used by “paint” Downside? Back to similar performance issues as tiled graphs • programs to flood fill color Upside? Can often generate automatically using “flood fill” (next slide) • 13 14 Path Finding in Finely Grained Graph Problem: Kinky Paths Problem: Path chosen “kinky”, not natural Use A* or Dijkstra depending on whether looking for specific or • multiple general targets Solution? Path smoothing. – e.g., Find exit? A* typically faster than Dijkstra’s since latter is - Simple fix to “penalize” change in direction exhaustive - Others work better (next) – e.g., Find one of many rocket launchers? A* would need to be re- run for each, then chose minimum. 15 16 Simple Smoothing Algorithm (1 of 2) Simple Smoothing Algorithm (2 of 2) 1. Grab source E1 2. Grab destination E2 3. If agent can move between, E2 E1 a) Assign destination E1 to E1 destination E2 b) Remove E2 c) Advance E2 E2 E1 E1 4. If agent cannot move a) Assign E2 to E1 b) Advance E2 • Check for “passability” between adjacent edges 5. Repeat until destination E1 or destination E2 is endpoint • Also known as “ray-cast” since if can cast a ray between A and C then waypoint B is not needed 17 3

  4. 3/21/2016 Path Smoothing Example Outline • Introduction (done) • Navigation Graphs (done) • Navigation Mesh (next) • Pathfinding Tuning • Pathfinding in UE4 E1 DEMO (SMOOTH) 19 NavMesh Example (1 of 3) Navigation Mesh (NavMesh) • Partition open space into network of convex polygons – Why convex? � guaranteed Waypoint path from any point to any point inside • Instead of network of points, have network of polygons (Part of Stormwind City in World of WarCraft) • Can be automatically generated from arbitrary • NavMesh has more NavMesh polygons information (i.e., can • Becoming very popular walk anywhere in (e.g., UE4) polygon) 21 http://www.ai-blog.net/archives/000152.html NavMesh Example (2 of 3) NavMesh Example (3 of 3) Waypoint Waypoint (The town of Halaa in World of WarCraft, seen (The town of Halaa in World of WarCraft, seen from above (slightly modified)) from above (slightly modified)) • Waypoint needs lots of NavMesh • Plus smoothing, else NavMesh points zigzag • NavMesh needs fewer • Note, smoothing for polygons to cover same navmesh works, too area http://www.ai-blog.net/archives/000152.html http://www.ai-blog.net/archives/000152.html 4

  5. 3/21/2016 NavMesh Performance NavMesh with other Paths • But isn't it slower to do • NavMesh can be used pathfinding on NavMesh? with waypoints • No. NavMesh is also a graph, just like waypoints. • Use waypoints for • Difference? Navmesh has higher-order locations polygon at each graph – E.g., node • Soldiers need patrol path • A* runs on any graph • Old man needs fishing – Square grid (Various terrain markers (AI hints) and NavMesh) path – Waypoint (Illustration of graph (red) underlying a • Cover points for hiding – Navmesh navigation mesh) • NavMesh to get there http://www.ai-blog.net/archives/000152.html http://www.ai-blog.net/archives/000152.html Outline Generating NavMesh • Introduction (done) • Can be generated by hand – e.g., lay out polygons (e.g., squares) to cover • Navigation Graphs (done) terrain for map • Navigation Mesh – Takes a few hours for typical FPS map – Generating a NavMesh (next) • Can be generated automatically • Pathfinding Tuning – Various algorithm choices • Pathfinding in UE4 – One example [Leo14] [Leo14] Timothy Leonard. “Procedural Generation of Navigation Meshes in Arbitrary 2D Environments”, Open Journal Systems Game Behavior , Volume 1, Number 1, 2014. Online: http://computing.derby.ac.uk/ojs/index.php/gb/article/view/13 Generating NavMesh – Contour Generating NavMesh – Walkable Area • Run marching squares to get contour – “marching squares” is graphics algorithm that generates contours for 2d field – Parallelizes really well Base background (just for show) Walkable area (white) • Contour points used as vertices for triangles for • Use collision grid to compute walkable area After running marching squares. Purple dots NavMesh – Prepare 2d array, one for each pixel show contour of walkable area. – Sample each pixel � if collide, then black else white 5

Recommend


More recommend