1 / 99

Graphs, Goals and NPCs

Graphs, Goals and NPCs. Advanced Programming for 3D Applications CE00383-3. Path Planning and Search. Solution Path. Spatial Environment. discretisation. Grid of cells mapped on the environment. Search Tree. search. Path. Overview. Alternative Search Space Representations Grids

baris
Download Presentation

Graphs, Goals and NPCs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphs, Goals and NPCs Advanced Programming for 3D Applications CE00383-3

  2. Path Planning and Search Solution Path Spatial Environment discretisation Grid of cells mapped on the environment Search Tree search Path

  3. Overview • Alternative Search Space Representations • Grids • Graphs • Meshes… • When we know what the world looks like, how can we move through it? • A* • Precomputed Pathfinding with Navigation Sets • Potential Fields

  4. Introduction • In many video games, artificial characters have to find their way through spatial layouts: • rooms (DOOM-like games) • terrain models, maps, etc. (strategy games)

  5. Search & Path Planning • A significant number of games involve moving in buildings, battlefields, etc. • Choosing the best path within a determined space is a classic AI problem • Algorithms have been developed that “construct” the best path by exploring possible directions on the basis of individual cells’ properties

  6. Discretisation grid cells hexagonal cells G 3D discretisation S

  7. Regular Grids

  8. Regular Grids • How do we generate? • Advantages • Random access lookup (O(1)) to determine what tile lies at any coordinate • Complete • Negatives • Usually requires large number of nodes to accurately represent world • Path Quality • Agent can only walk in four cardinal directions? That’s no fun. • Let them walk diagonals! Still not much fun

  9. Regular Grids NWSE Diagonals String-Pulling Catmull-Rom Spline

  10. Grids as Graphs • Everything else we look at will be a graph • Grids are graphs too • Each cell is a node and edges are adjoining cells • Maybe we should just handle grid as a graph • Undirected graph could tell us about topography, etc, whereas array can’t

  11. Grids as Graphs

  12. Corner Graphs • Waypoints around obstacles

  13. Corner Graphs • How do we generate? • Identify convex corners, can character walk in straight line between? Add edge if possible • Advantages • Less memory • Faster generation • Negatives • Character will “walk on a rail” hugging edges of obstacles instead of walking through open space • And what about different sized characters? • Lookup is O(n2), have to check every node in graph against every other. Imagine a world with a boat load or corners!

  14. Corner Graphs

  15. Corner Graphs

  16. Waypoint Graphs • Place nodes in middle of rooms instead of at convex corners

  17. Waypoint Graphs • How do we generate? • Place nodes wherever we want (suits 3-D worlds  But requires hand tuning to be effective ) • Advantages • Reduce memory footprint from regular grids, reduce wall hugging from corner graphs • Work well in “human” architectures • Negatives • Still O(n2) • Path Quality vs. Simplicity • Works poorly in open areas

  18. Waypoint Graphs

  19. Circle-Based Waypoint Graphs • Add radius parameter to indicate open space near waypoint

  20. Circle-Based Waypoint • Advantages • Only look at overlapping circles, alleviating O(n2) problem from before • Easier to obtain optimal paths • Works well in open terrain • Negatives • Doesn’t work as well in human architectures that aren’t circle friendly

  21. Space-Filling Volumes • Use rectangles or 3-D Boxes instead of circles

  22. Space-Filling Volumes • How do we generate? • Seed and Grow • Make Grid and Merge • Very similar to circle-based, but handles angles better

  23. Navigation Meshes • Let’s try and cover walk able surfaces with convex polygons • Character can travel between adjoining polygons

  24. Navigation Meshes

  25. Navigation Meshes • How do we generate? • By hand (time consuming) • Automated tools to analyze and optimize geometry of world • Too complex and not represented as a single polygon mesh, instead may be overlapping, etc

  26. Navigation Meshes • Advantages • Quickly find optimal paths independent of character shapes and capabilities • Handle indoor and outdoor terrains well • Negatives • Can become complex and expensive memory wise • Difficult to generate

  27. Problem with N-Sided Meshes

  28. Interacting with Pathfinding • What about dynamic objects in world? • All the representations discussed have been static and obviously can’t handle a dynamic world directly • These representations need to be able to provide information to system determining path • Waypoint Graphs and Corner Graphs don’t illustrate walk able surfaces • Meshes and Grids do map every walk able surface • Space-filling volumes and Circle Waypoints provide some representation of walk able areas

  29. Path finding • Now that we have world represented, how do we plan movement? • A*, Depth-First, Dijkstra • Dynamic path finding is expensive • Precompiled solutions can eliminate runtime cost, but memory expensive • Article suggests technique of Navigation Set Hierarchy

  30. Path finding • Determine best paths leading from source node to boundary of source set • Determine best path from source set boundary to goal set boundary • Determine best path from goal set boundary to goal node • Compile list of complete paths and choose one with least cost

  31. Transition Table • Main element in pre computed solutions is a lookup table • Each entry represents next step to take from one node to some goal node

  32. Transition Table

  33. Transition Table • Do not need full search of nodes at run time, just series of lookups • Fast, but becomes memory expensive as size of world grows • How expensive? n2 • …solution to shrink transition tables? Hierarchy!

  34. Navigation Set • Self-contained collection of nodes that requires no links to external nodes to complete a path • Nodes can be members of more than one set • Goal: Find someway to partition large Navigation Sets into smaller ones

  35. Complete Hierarchy

  36. Interface Nodes and Sets • Need to account for paths that cross navigation sets • Any node that connects to a node in another navigation set is an interface node • Have a second layer of nodes in addition to navigation sets, called interface set • Interface set itself is a navigation set • Therefore, can make transition table for it too

  37. Complete Hierarchy • 21 nodes • 1 Navigation Set = 441 Table Entries (21*21) • 4 Navigation Sets = 183 Table Entries (7*7 + 7*7 + 7*7 + 6*6)

  38. Constructing the Hierarchy Two goals to process • How many tables to create? • Amount of data needed is 1/n of original size + interface set • As size of navigation sets increase, cost of interface set becomes less a factor • Where to place boundaries? • Keep interface nodes as low as possible

  39. Constructing the Hierarchy

  40. Potential Fields • Reactive approach to path finding • Setup virtual potential or force field around objects • Must define field and agents reaction to field • Interactions in general are explicitly stated and movement “emerges” • Paths are not planned explicitly

  41. Potential Fields • Think of world as matrix • Each point tells has value to represent strength of field under it • Possibly assign potential based on distance from goal • Might get stuck behind obstacle • Result/Goal: “Glide down gradient/path of least resistance”

  42. Potential Fields • Advantages? • Works in continuous space! No need to make grid, place waypoints, etc • Disadvantages? • Can be trapped in local minima • It’s emergent, not sure what it will do

  43. Path planning on a grid (1/2) • Going from A to B avoiding obstacles • It is only possible to move from one cell to an adjacent cell • How to find: • the shortest path? • In the shortest time? • At the lesser cost? B A

  44. B A Path planning on a grid (2/2) • From each node of the grid, it is possible to go only to neighbouring nodes • Path planning is the process by which a path is assembled from A to B through authorised moves

  45. Search Trees • From a given node, it is possible to generate a set of neighbours. For instance a given node on the grid has for neighbours corresponding to the N, S, E, W, NW, NE, SE, SW moves • The process of generating all the neighbours of a given node is called node expansion.

  46. Grid Moves and Search Trees B path A

  47. Search Algorithms and Path Planning • Because the path on the grid is formally equivalent to a path on the tree, tree-searching algorithms can be used for path planning • The path found on the tree does correspond to a path on the grid, hence in the game environment

  48. Why Search? • Search is a key technique for AI, in particular real-time AI • Applications in computer games include: • Path planning • Moving Target Search • Two-player games (othello, chess, etc.) • Search-based planning for animation or intelligent actor behaviour

  49. Search • Search consists of a set of technique that explore graphs and extract solutions, i.e. sub-graphs satisfying some desirable properties • Solutions can be: • Nodes (e.g. n-queens) • Paths (e.g. n-puzzle)

  50. State-space Search • In the state space representation of a problem, the nodes correspond to partial problem solution states and the arcs correspond to steps in the problem solving process (or operators) • This makes possible to apply the same graph-search algorithms for finding a solution to these problems (various optimisation problems, games, etc.)

More Related