Path Planning Part I: Search Space Representation Part II: Table Lookup Path Finder Path III: Convincing Hunting Ref: AIWisdom 2
Spring Taxonomy Local path finding For dynamic environment [characters in motion, obstacles moved by characters] potential energy, steer, … Global path planning For static environment Graph-based search algorithm (Dijkstra, A*, BFS, … )
Spring Task Decomposition Search Space Representations: ways to define the waypoints Search Algorithms Extension: mixed with local algorithm …
Spring Search Space Representations Analogy: C++ STL: algorithms (sort, find, copy, … ) work on various container classes (vector, list, … ) Path finding: algorithms (BFS, DFS, Dijkstra, A*, … ) Search space representation: … Choice of representation has great impact on performance and memory overhead Assumption: 2D, or 3D hovering at fixed height Full 3D: flying, swimming characters
Spring Introduction All search spaces are graphs: nodes and edges Problem definition (Path Optimality): given two points A and B, find the least expensive path from A to B Remarks: not always the shortest [consider swamp] Must consider agent movement capability [size, open door, swim, climb, … ]
Spring Character-dependent Paths
Spring Search Space Generation Options: manually created by level designer Automatically generated by programs “ The AI is broken in your level because you put the path node in the wrong place …” jeopardize the workflow
Spring Types of Representation Regular grid (square, hexagonal) Corner graph Waypoint graph [circle-based] Space-filling volume Navigation Mesh [triangle or poly- based] Understand the pros and cons Smooth technique (string-pulling) Hierarchical representation (thousands of waypoints … )
Spring Example Scene
Spring Regular Grid Simplest way: grid of squares, rectangles, triangles, hexagons, … Large number of grid cell (large memory footprint) Easy for “ random- access lookup ”
Spring Regular Grid (cont) Quality of path 4-way access Allow diagonal
Spring String-Pulling Line-of-sight test: remove P n if P n+1 is visible from P n-1 Can be very expensive Use Catmull-Rom spline to create a smooth curved path
Spring Alternative: Chase the Point Instead of tracking along the path, the agent chases a target point that is moving along the path Start with the target on the path ahead of the agent At each step: Move the target along the path using linear interpolation Move the agent toward the point location, keeping it a constant distance away or moving the agent at the same speed Works best for driving or flying games
Spring Chase the Point Demo
Spring Remark Grid, though seemingly can be implemented as arrays, should be implemented as (directed) graph: path can be directional A B C D
Spring Corner Graph Way points placed at convex corners of the obstacles O(n 2 ) complexity to determine edges in the graph Create sub optimal path Character walk very close to the wall (unnatural) different sized character requires different set of waypoints …
Spring Waypoint Graph Similar to corner graph; but waypoints are usually placed in the middle of rooms and hallways Also suffer from the O(n 2 ) complexity issue Works well in human architecture; tend to work poorly in large rooms and open terrain Usually require hand-tuning by level designer to perform well
Spring Circle-based Waypoints Try to resolve the O(n 2 ) complexity Add to each way point a radius parameter: indicate the amount of open space around it Generate edges between node pairs whose circles overlap Works well in open terrain, but in angular environment circles may not fill well (shown in figure)
Spring Space-Filling Volumes Ways of generation: drop-and-grow; merge from grid Works better (cp. circle-based) for angular environment
Spring NavMesh Cover the game world with convex polygons Handles indoor and outdoor terrain equally well Require storage of large number of polygons Convexity is required because … Triangulation, trapezoidalization
Spring Modified String-Pulling Besides eliminating unnecessary points on the path, path points can move along the link (shared edge) between two nodes
Spring Hierarchical Representation Break the navigation problem into levels [library in NYC to a diner in Seattle] Key step: identify zones; cluster nodes in search graph Indoor scene: use portal information
Navigation Set Hierarchy
Spring Introduction Developers are spending more resources in the attempt to deliver interesting and complex AI behavior Basic functions like path-finding should be cheap Precomputing navigation accomplishes this, with a price: memory
Spring Basics: The Transition Table Table requires n 2 entries
Spring Hierarchy Navigation set: a self-contained collection of nodes that requires no links to external nodes in order to complete a path from one internal nodes to another Interface nodes: the connective boundaries between navigation sets Interface set
Spring Example
Spring Constructing the Hierarchy Partitioning by automated means is a complex problem ! Objective: keep the number of interface nodes as low as possible Identify “ choke points ”
Spring Complete Path Planner Source & goal in same NavSet: trivial Four-step solution Source to boundary set Tier-2 paths: interface nodes Boundary set to Target From combinations; select the one with least cost Performance depends on the number of interface nodes in the source and goal sets only
Spring Example A3 A6 A7 C3 C5 C7
Spring Memory Optimization In the transition table, instead of storing node indices (which can be large and requires more bits), store edge indices (edge that lead to the node) I doubt this will work. How to know which node a particular edge leads to?
Hunting Down the Player in a Convincing Manner
Spring Introduction Require NPCs to convincingly chase and hunt down the player When a guard has spotted the player, he begins pursuit Routing player ’ s position to a path planner generate a shortest-path may let the player feel cheated Interesting game play: lure the NPC into regions then double back to escape
Spring Facility: Know the positions of target player and hunting character (NPC) Visibility test from NPC to player Three scenarios Player is visible (by the NPC) Player was recently seen Player has never been seen
Spring Scenarios Scenario One: Change from hunting state to attack state Scenario Two: NPC moves to the last seen player location, should be stored by game engine
Spring Scenario Three Create intermediate destination to approach the player Generate random direction and travel distance Successive application