basic methods pathfinding. different types of pathfinding problems exist no one solution...

Click here to load reader

Upload: elyse-awbrey

Post on 16-Dec-2015

237 views

Category:

Documents


0 download

TRANSCRIPT

  • Slide 1
  • Basic Methods Pathfinding
  • Slide 2
  • Different types of pathfinding problems exist No one solution appropriate to every problem! Qs: Is the destination moving or stationary? Are there obstacles? What is the terrain like? Is the shortest solution always the best solution? Is it required to reach a specific destination or just a partial route will do? What map representation is used?
  • Slide 3
  • Pathfinding You have heard of the A* Algorithm, the most popular & famous pathfinding algorithm But we will first look at some basic pathfinding methods (that are not as complex as A*and more suitable than A* in various situations) A* will be covered in the next lesson
  • Slide 4
  • Basic Pathfinding The most simple, easiest and fastest solution to pathfinding is to re-use the Chase movementbut chase a destination position! if(positionX > destinationX) positionX--; else if(positionX < destinationX) positionX++; if(positionY > destinationY) positionY--; else if(positionY < destinationY) positionY++; Probably produces the most unnatural-looking path
  • Slide 5
  • Basic Pathfinding OK, the better approach would be to use the Line-of-Sight Chase to get a more natural path (using line-drawing algorithm on TBE and steering forces on CE) However, these methods are not suitable for certain scenarios. Can you figure out?
  • Slide 6
  • Obstacles? Problems with obstacles Random Movement Obstacle Avoidance Simple and effective method Works well in environments with relative few obstacles if Player In Line of Sight Follow Path to Player else Move in Random Direction
  • Slide 7
  • Tracing Around Obstacles Another simple method Tracing Around Obstacles When encounter obstacle, switch to tracing state Tracing follows the edge of the obstacle to work way around it
  • Slide 8
  • Tracing Around Obstacles Another simple method Tracing Around Obstacles When encounter obstacle, switch to tracing state Tracing follows the edge of the obstacle to work way around it Basic Tracing Movement:
  • Slide 9
  • Tracing Around Obstacles We need to decide WHEN to STOP tracing! One easy way: Calculate a line from the point the tracing starts to the desired destination Continue Tracing until that line is crossed, then revert back to L-o-S pathfinding Improved Tracing:
  • Slide 10
  • Tracing Around Obstacles Incorporate line-of-sight with tracing method At each step of tracing state, utilize line-of-sight to determine if a straight line-of-sight path can be followed to reach destination immediately If a line-of-sight path is possible, switch back to line-of-sight pathfinding state Tracing with Line-of-Sight:
  • Slide 11
  • Breadcrumb Pathfinding Able to make NPCs appear intelligently, because the player is unknowingly creating the path for the NPC! Each time the player takes a step, he leaves an invisible marker or breadcrumb in the game world Breadcrumb trail:
  • Slide 12
  • Breadcrumb Pathfinding When the NPC encounters a breadcrumb, it simply begins to follow the trail until the end In a real game, the number of breadcrumbs dropped will depend on the game and how smart you want the NPCs to appear. The player never sees the breadcrumb trail!
  • Slide 13
  • Breadcrumb Pathfinding Implementation Begin by creating a trail row and column arrays and setting each element value to -1 Checks for the players direction key presses and records them down dropping a breadcrumb Since there is a max trail length, the oldest position will be dropped so that a new position can be added
  • Slide 14
  • Following the breadcrumbs Example: Troll moves randomly (8 possible directions) Loop through the trail locations to determine if the troll has moved into a breadcrumb location If a breadcrumb is found, set the troll to use the path
  • Slide 15
  • Following the breadcrumbs Due to possibility that the players path overlap itself or adjacent to previous location in path Not Smart: NPC ends up taking exact footsteps of player Solution: Allow NPC to always look for adjacent tile containing the most recent breadcrumb, skipping over breadcrumbs
  • Slide 16
  • Path Following (in TBE) To confine a NPC to a certain terrain element such as road, we can use terrain labeling Example: Labeling road terrain tiles as 2s and other out-of- bounds terrain as 1s
  • Slide 17
  • Path Following (in TBE) We do NOT want to make it move randomly allow the road tiles Unnatural From 8 possible directions to move, eliminate those that are not part of the road. Then, decide on which of the remaining directions to take Set neighboring road tiles to a big number and those out-of- bounds to 0. Tip: Keep the NPC moving in the same general direction, turn only when have to Tip: Assign a number to each direction
  • Slide 18
  • Path Following (in TBE) Weigh the directions so that priority will be given to maintaining previous direction Example: Current direction: 1 Traverse the direction array in search for the most highly weighted direction, move to that direction in the next step
  • Slide 19
  • Path Following (in TBE) How do we increase the robustness of this path following movement (to look more natural and intelligent)?
  • Slide 20
  • Wall Tracing Does not calculate path from a starting to ending point Most useful in game environments with many rooms or mazes Obstacle tracing (discussed earlier) can also be used to trace walls Random movement in such environments is commonly used to increase uncertainty but NPCs often get stuck in small rooms for long periods of time
  • Slide 21
  • Wall Tracing How to make the troll EXPLORE and move in a systematic way around this environment?
  • Slide 22
  • Wall Tracing Simple solution Left-handed approach If the NPC always move to the left, it will do a thorough job exploring the environment Move LEFT WHENEVER POSSIBLE (Remember: Left of the NPC, not the player!) Example: NPC facing players right Direction 2 is the NPCs LEFT If that is blocked try STRAIGHT, then try RIGHT If still blocked, choose to reverse BACK
  • Slide 23
  • Wall Tracing Implementation: 4 IF-ELSE blocks to check for the directions to take (8 if accommodating all 8 directions!) Should be able to traverse almost every room, but not guaranteed to work in all geometries!
  • Slide 24
  • Waypoint Navigation Pathfinding Time-consuming, CPU-intensive operation To reduce this burden: Pre-calculate paths Waypoint Navigation Carefully place nodes in the game environment, then use pre-calculated paths or other inexpensive methods to move between each node. Useful for both TBE and CE (plus point!) Example: Placing suitable nodes on a simple map with 7 rooms What can you observe from these 7 nodes???
  • Slide 25
  • Waypoint Navigation Every node is in the line-of-sight of at least ONE node! Setting up like this, a NPC is able to reach every single room in the world using simple line-of-sight algorithm Game AI just needs to know HOW the nodes are connected to one other
  • Slide 26
  • Waypoint Navigation Using node labels and links, we can now determine a path from any room to any room Example: Moving from room with node A to room with node E Move following ABCE path
  • Slide 27
  • Waypoint Navigation Can these different paths between rooms be PRE-calculated beforehand? If NO, WHY? If YES, HOW?
  • Slide 28
  • Waypoint Navigation To move from node to node, determine the node that is nearest to the players location and in players line-of-sight Use a lookup table to store data of shortest paths between any two nodes Establish the connections between nodes Left side: Starting nodes Top side: Ending nodes Determine best path by looking at intersection on the table between starting and ending nodes
  • Slide 29
  • Waypoint Navigation We can discover the connections and fill in the table either 1) manually or 2) by simulated traversal of nodes Example: Moving from A to all other nodes resulted in B as the nearest node
  • Slide 30
  • Waypoint Navigation Continue doing this until the entire node connection table is completed
  • Slide 31
  • Waypoint Navigation Example: Determine path from node B (triangle) to node G (square) by repeatedly finding the intersection, starting with nodes B and G. Using the intersected nodes as the subsequent locations to move on
  • Slide 32
  • Waypoint Navigation Post-mortem Question 1: What are some drawbacks of this method? Question 2: Are there ways to improve this current method of waypoint navigation
  • Slide 33
  • Next A* Algorithm An extremely popular pathfinding algorithm used widely in games Map Representations for A* Pathfinding (Grids, Polygonal Maps, Navigation Meshes, Hierarchical)