Pathfinding: Search Space Representations Chapter 2.1 Dan Bader.
-
Upload
melvin-obrien -
Category
Documents
-
view
219 -
download
3
Transcript of Pathfinding: Search Space Representations Chapter 2.1 Dan Bader.
Pathfinding:Pathfinding:Search Space Search Space
RepresentationsRepresentationsChapter 2.1Chapter 2.1
Dan BaderDan Bader
Chapter written by Paul TozourChapter written by Paul Tozour
Designed and developed a shared AI platform Designed and developed a shared AI platform for Thief 3 and Deus Ex 2: Invisible Warfor Thief 3 and Deus Ex 2: Invisible WarDeveloped the combat AI systems for Developed the combat AI systems for Microsoft's MechWarrior 4: VengeanceMicrosoft's MechWarrior 4: VengeanceFounding member of Gas Powered GamesFounding member of Gas Powered GamesDesigned and programmed a real-time strategy Designed and programmed a real-time strategy game called WarBreedsgame called WarBreedsHas also written numerous AI articles for the Has also written numerous AI articles for the Game Programming Gems and AI Game Game Programming Gems and AI Game Programming Wisdom series Programming Wisdom series
Performance and Memory Performance and Memory OverheadOverhead
Pathfinding algorithm only half the picturePathfinding algorithm only half the picture
Underlying data structure is just as Underlying data structure is just as importantimportant
Comparable to using sort(), find(), copy() Comparable to using sort(), find(), copy() C++ Standard Template library functions C++ Standard Template library functions with different container types (lists, with different container types (lists, vectors, etc.)vectors, etc.)
Different performance characteristicsDifferent performance characteristics
Goal: Find representation thatGoal: Find representation that
Fits within a reasonable amount of Fits within a reasonable amount of memorymemory
Gives us the fastest possible search timeGives us the fastest possible search time
Some properties of all Some properties of all representationsrepresentations
Fundamentally a Search Space can be viewed Fundamentally a Search Space can be viewed as a graphas a graph Has some atomic unit of navigation: nodeHas some atomic unit of navigation: node Some number of connections between nodes: edgesSome number of connections between nodes: edges
Large graphs take up lots of memory and slow Large graphs take up lots of memory and slow performance (more nodes/edges cause larger performance (more nodes/edges cause larger search space)search space)Smaller simpler graphs leave smaller memory Smaller simpler graphs leave smaller memory footprint, but run the risk of not accurately footprint, but run the risk of not accurately representing the game world (too simple)representing the game world (too simple)
Goal of Pathfinding algorithmsGoal of Pathfinding algorithms
Optimal path = not always straight lineOptimal path = not always straight line Travel around swamp versus through itTravel around swamp versus through it
““Least expensive” pathLeast expensive” path
Trade off between simplicity and optimality Trade off between simplicity and optimality (too simple a representation and (too simple a representation and pathfinding will be fast, but will not find pathfinding will be fast, but will not find very high quality path)very high quality path)
Capabilities of AICapabilities of AI
Different characters have different Different characters have different movement capabilities and a good movement capabilities and a good representation will take that into accountrepresentation will take that into account Agents ask “Can I exist there?”Agents ask “Can I exist there?” Large monsters can’t move through narrow Large monsters can’t move through narrow
walkwayswalkways
Another GoalAnother Goal
Search Space generation should be Search Space generation should be automaticautomatic Generate from world’s raw geometry or from Generate from world’s raw geometry or from
physics collision meshphysics collision mesh Manual node placement must be done for all Manual node placement must be done for all
world pieces. Takes time and effortworld pieces. Takes time and effort
Scripted AI PathsScripted AI Paths
Search Space representation is different Search Space representation is different than patrol path creation toolthan patrol path creation toolDesigners want predefined patrol paths, Designers want predefined patrol paths, so they script themso they script them Works well only in predefined sequencesWorks well only in predefined sequences Not good for interactive behavior (i.e. combat, Not good for interactive behavior (i.e. combat,
area-searching)area-searching)
Keep scripted patrol sequences separate Keep scripted patrol sequences separate from search spacefrom search space
Regular GridsRegular Grids
Won’t work for 3D game worlds without some Won’t work for 3D game worlds without some modificationmodificationMostly used in strategy games (typically with a Mostly used in strategy games (typically with a top-down perspective) top-down perspective) Civilization 3 displays only four sides to each Civilization 3 displays only four sides to each cell, but actually can move in 8 directions (along cell, but actually can move in 8 directions (along the diagonals)the diagonals)Disadvantage: High resolution grids have large Disadvantage: High resolution grids have large memory footprintmemory footprintAdvantage: Provide random access look-upAdvantage: Provide random access look-up
Grids and MovementGrids and Movement
Moving in only 4 cardinal directions gives Moving in only 4 cardinal directions gives you unattractive angular pathsyou unattractive angular paths
Grids and MovementGrids and Movement
Add in the diagonals and you improve the Add in the diagonals and you improve the movement somewhatmovement somewhat
An OptimizationAn Optimization
String-pulling or Line-of-sight testing can String-pulling or Line-of-sight testing can be used to improve this furtherbe used to improve this further
Delete any point PDelete any point Pn n from path when it is from path when it is possible to get frompossible to get from PPn-1n-1 to to PPn+1 n+1 directlydirectly
Don’t need to travel through node centersDon’t need to travel through node centers
Another OptimizationAnother Optimization
Use Catmull-Rom splines to create a Use Catmull-Rom splines to create a smooth curved pathsmooth curved path
GraphsGraphs
The rest of the search space representations The rest of the search space representations are graphsare graphs
You can think of grids as graphsYou can think of grids as graphs Could be useful to have directed graphs (cliffs)Could be useful to have directed graphs (cliffs)
Corner graphsCorner graphs
Place waypoints on the corners of obstaclesPlace waypoints on the corners of obstacles
Place edges between nodes where a Place edges between nodes where a character could walk in a straight line between character could walk in a straight line between themthem
Corner GraphsCorner Graphs
Sub-optimal pathsSub-optimal paths
AI agents appear to AI agents appear to be “on rails”be “on rails”
Corner Graphs and String-pullingCorner Graphs and String-pulling
Can get close to the optimal path in some cases with Can get close to the optimal path in some cases with String-pullingString-pullingRequires expensive line-testingRequires expensive line-testing
String-pulling
Waypoint GraphsWaypoint Graphs
Work well with 3D games and tight spacesWork well with 3D games and tight spaces
Similar to Corner GraphsSimilar to Corner Graphs Except nodes are further from walls and obstaclesExcept nodes are further from walls and obstacles Avoids wall-hugging issuesAvoids wall-hugging issues
Waypoint GraphsWaypoint Graphs
Cannot always find optimal path easily, even Cannot always find optimal path easily, even with string-pulling techniqueswith string-pulling techniques
Circle-based Waypoint GraphsCircle-based Waypoint Graphs
Same as waypoint graphsSame as waypoint graphs Except add a radius around each node indicating Except add a radius around each node indicating
open spaceopen space
Adds a little more information to each nodeAdds a little more information to each nodeEdges exist only between nodes whose circles Edges exist only between nodes whose circles overlapoverlapSeveral games use a hybrid of Circle-based Several games use a hybrid of Circle-based waypoint graphs and regular waypoint graphs, waypoint graphs and regular waypoint graphs, using Circle-based for outdoor open terrain and using Circle-based for outdoor open terrain and regular for indoor environmentsregular for indoor environments
Circular Waypoint GraphsCircular Waypoint Graphs
Good in open terrainGood in open terrain
Not good in angular game worldsNot good in angular game worlds
Circular Waypoint GraphsCircular Waypoint Graphs
Good in open terrainGood in open terrain
Not good in angular game worldsNot good in angular game worlds
Y
Space-Filling VolumesSpace-Filling Volumes
Similar to Circle based approach, but use Similar to Circle based approach, but use rectangles instead of circlesrectangles instead of circles
Work better than circle based in angular Work better than circle based in angular environments, but might not be able to environments, but might not be able to completely fill all game worldscompletely fill all game worlds
Navigation MeshesNavigation Meshes
Handles indoor and outdoor environments Handles indoor and outdoor environments equally wellequally well
Cover walkable surfaces with convex Cover walkable surfaces with convex polygonspolygons
Requires storage of large number of Requires storage of large number of polygons, especially in large worlds or polygons, especially in large worlds or geometrically complex areasgeometrically complex areas
Used in Thief 3 and Deus Ex 2 (video)Used in Thief 3 and Deus Ex 2 (video)
NavMeshNavMesh
Polygons must be convex to guarantee Polygons must be convex to guarantee that an agent can walk from any point that an agent can walk from any point within a polygon to any other point within within a polygon to any other point within that same polygonthat same polygon
Is possible to generate NavMesh with Is possible to generate NavMesh with automated tool (was done in Thief 3 and automated tool (was done in Thief 3 and Deus Ex 2) – difficultDeus Ex 2) – difficult
2 types of NavMeshs2 types of NavMeshs
Triangle basedTriangle based All polygons must be trianglesAll polygons must be triangles When done correctly, will not hug walls too tightlyWhen done correctly, will not hug walls too tightly
N-Sided-Poly-basedN-Sided-Poly-based Can have any number of sides, but must remain Can have any number of sides, but must remain
convexconvex Can usually represent a search space more simply Can usually represent a search space more simply
than triangle based (smaller memory footprint)than triangle based (smaller memory footprint) Can lead to paths that hug walls too tightlyCan lead to paths that hug walls too tightly
Interacting with local pathfindingInteracting with local pathfinding
Pathfinding algorithm must be able to deal Pathfinding algorithm must be able to deal with dynamic objects (things player can with dynamic objects (things player can move)move)
Can use simple object avoidance systems, Can use simple object avoidance systems, but can break down in worlds with lots of but can break down in worlds with lots of dynamic objectsdynamic objects
Interacting with local pathfindingInteracting with local pathfinding
Search Space is static, so it can’t really Search Space is static, so it can’t really deal with dynamic objectsdeal with dynamic objects
Should design it to give some information Should design it to give some information to pathfinding algorithm that will helpto pathfinding algorithm that will help
““Can I go this way instead?” – search Can I go this way instead?” – search space should be able to answer thisspace should be able to answer this
Hierarchical RepresentationsHierarchical Representations
Break navigation problem down into levelsBreak navigation problem down into levels
Was discussed in previous lectures by Prof. Was discussed in previous lectures by Prof. MunozMunoz
Paul Tozour may have done this too much in Paul Tozour may have done this too much in Thief 3 for the CityThief 3 for the City ““game environments just don't seem big enough from game environments just don't seem big enough from
one loading screen to the next” – Gamespot reviewone loading screen to the next” – Gamespot review When trying to move quickly through the City, loading When trying to move quickly through the City, loading
times detract from gameplaytimes detract from gameplay
ConclusionConclusion
There is no right or wrong way to design There is no right or wrong way to design search space representationssearch space representations Should depend on world layout, your AI Should depend on world layout, your AI
system and pathfinding algorithm, and also system and pathfinding algorithm, and also memory and performance criteriamemory and performance criteria
Understand benefits and drawbacks and Understand benefits and drawbacks and make the best choice based on thatmake the best choice based on that
Paul TozourPaul Tozour
““The system I designed for Thief 3 and Deus Ex 2 stored The system I designed for Thief 3 and Deus Ex 2 stored enough data in the NavMesh that units could create enough data in the NavMesh that units could create paths appropriate to their individual capabilities. A very paths appropriate to their individual capabilities. A very tall unit would be able to query each node/polygon of the tall unit would be able to query each node/polygon of the NavMesh to know that it couldn't fit through a crawlshaft. NavMesh to know that it couldn't fit through a crawlshaft. A fat NPC would be able to query the width of a doorway A fat NPC would be able to query the width of a doorway and know that it had to go another way. A character with and know that it had to go another way. A character with very large, flat feet would know that it can't go up tall very large, flat feet would know that it can't go up tall stairs or on steeply sloped surfaces. And so on.stairs or on steeply sloped surfaces. And so on.
The key is, if you represent the data in the right way, you The key is, if you represent the data in the right way, you can query it in your A* pathfinder to make sure that a can query it in your A* pathfinder to make sure that a given NPC will only create a path that it knows matches given NPC will only create a path that it knows matches its particular movement/steering capabilities.”its particular movement/steering capabilities.”