Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence in Game Design Dynamic Path Planning Algorithms.

Similar presentations


Presentation on theme: "Artificial Intelligence in Game Design Dynamic Path Planning Algorithms."— Presentation transcript:

1 Artificial Intelligence in Game Design Dynamic Path Planning Algorithms

2 Dynamic Path Planning Not always plausible for NPC to have complete map for path planning “Fog of war” –Player can only view part of map they have explored –Same should be true for NPC Paths may change dynamically –Paths between moving cars –Must reevaluate paths each frame

3 Map Exploration Key idea: NPC only has map of some waypoints NPC can still use heuristic to estimate distance from waypoints to goal in unexplored areas explored Goal in unexplored area Have heuristic estimate of distance to it from waypoint Waypoint in explored area Know shortest path to here

4 Map Exploration NPC should not know waypoints and edge costs until they have explored an adjacent waypoint –Gathering information has cost of moving to that location Key question: Which waypoint should NPC move to next? explored Goal in unexplored area Have heuristic estimate of distance to it from newly found points Waypoint in explored area Reaching here has cost

5 Best-first Search Follow edge to waypoint with shortest estimated path to goal Difference from A*: –Path cost from initial location to current location W here not factored in –That cost already incurred by reaching current location Go to waypoint W next with minimum of: edgecost(W here, W next ) + H(W next, W goal )

6 Best-first Search Example 3 1 4 5 Chosen since 1 + 5 < 3 + 4 3 1 4 2 Chosen since 3 + 2 < 2 + 4 2 3

7 Backtracking (LRTA*) Heuristic may greatly underestimate actual distance to goal –High-cost terrain –Impassible obstacle in path Best path may involve returning to some previous waypoint and taking another route Backtrack to waypoint W prev if: edgecost(W here, W next ) + H(W next, W goal ) > pathcost(W here, W prev ) + H(W prev, W goal ) W goal W next W prev

8 Backtracking Example 3 1 4 1 2 3 20 15 2 Easy to reach, but on edge of cliff Estimated cost = 22 Close to goal, but requires crossing a river Estimated cost = 16 Best path involves backtracking to here Estimated cost = 5 + 4 = 9

9 Heuristics and Dynamic Pathfinding Heuristic estimates too high  may not find best path –May be plausible behavior for world with hidden passages or paths –Player can use knowledge of shortcuts to outrun NPC! 3 1 4 10 Chosen since 1 + 5 < 3 + 4 Shortcut has actual cost = 3

10 Heuristics and Dynamic Pathfinding Heuristic estimates too low  frequent backtracking –May be most plausible behavior for worlds with many obstacles –Can be amusing for player if done right! &*%!

11 Pathfinding in Dynamic Graphs Example: Racing games or other games involving traffic Problems: Waypoints are moving Edges between waypoints may only exist temporarily These waypoints are moving with car being passed This car may change lanes and cut off edge

12 Time-based Waypoints Waypoints have time as well as location property –Location of waypoint –Time at which the character reaches the waypoint –Only way to deal with moving waypoints Example: 2 different routes to same location W –Red route: reaches waypoint (W, 5) –Blue route: reaches waypoint (W, 7) 5 5 11 Same location but different time component

13 Time-based Waypoints Problem: potentially infinite number of waypoints at same location with different time components –Car can change lanes multiple times at any point –Can go faster or slower, resulting in different arrival times –Green route reaches (W, 9) Need heuristics to constrain choices –Often “greedy”, covering ground as fast as possible

14 Simplifying Assumptions Racing heuristics: If changing lanes, do so as soon as possible Once in lane, move at maximum speed to next lane change Change lanes as soon as safe Get here as fast as possible

15 Goal Points Paths change rapidly –Other cars change lanes –Other cars change speeds Can’t plan far in advance Must put goals at small intervals –Every few hundred feet on track (possibly at inflection points) –Every block in city –Not necessarily point

16 Safe Distances Choose waypoints based on “safe distance” from other cars –Usually defined by some “radius” around cars Can base safe radius on “personality” –Cautious –Normal –Aggressive –Psychotic Can’t get closer than this Can’t cut in front of this car Can cut in front of this car

17 Dynamic Waypoints Add waypoints for immediate lane changes from current position –Must be no cars within safe radius Must take into account velocity of car –Can’t move directly sideways! –Must take into account speeds of cars in way Distance traveled in time to change lane Waypoint here blocked Distance blocking car travels

18 Dynamic Waypoints Add waypoints for positions immediately behind car in same lane –Based on speed difference between cars Waypoint for Seek behavior without slowing down –Used if immediately steer into another lane without slowing down Waypoint for Arrive behavior with matching velocity –Pulling up behind car without collision Current position of other car Where other car will be if Seek without slowing down Where other car will be if Arrive while slowing down

19 Dynamic Waypoints Add waypoints for positions where car can cut in front of cars in adjacent lanes –Based on speed difference between cars –Can’t be past car in current lane No waypoints past this car

20 Dynamic Waypoints Example combining all above waypoints –Each other car shown at position where it will be at waypoint formation Waypoints for immediate lane changes Waypoints for passing this car Waypoint for passing car in front Waypoint for pulling up behind car in front

21 Creating Dynamic Graph Next step: Continue on from these waypoints to next waypoints Continue until nearest goal reached Goal

22 Finding Best Path Use Dijkstra or A* to find shortest path Recompute each frame since things change When reach this goal, start again for next goal Goal


Download ppt "Artificial Intelligence in Game Design Dynamic Path Planning Algorithms."

Similar presentations


Ads by Google