Pathfinding and Movement Michael Moll September 29, 2004.

50
Pathfinding and Movement Michael Moll September 29, 2004

description

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

Transcript of Pathfinding and Movement Michael Moll September 29, 2004.

Page 1: Pathfinding and Movement Michael Moll September 29, 2004.

Pathfinding and Movement

Michael MollSeptember 29, 2004

Page 2: Pathfinding and Movement Michael Moll September 29, 2004.

A Character Has to Move

• Amount of processing time per cycle for AI is low• While movement is obviously a vital part of a

game, it’s not exactly the most interesting task performed

• With A* as an example, plenty of algorithms to find paths, but probably less considered, but more important is

How will we represent space we move through??

Page 3: Pathfinding and Movement Michael Moll September 29, 2004.

Overview

• Alternative Search Space Representations– Grids– Graphs– Meshes…

• Ok, we know what the world looks like, how can we move through it?– A*– Precomputed Pathfinding with Navigation Sets– Potential Fields

Page 4: Pathfinding and Movement Michael Moll September 29, 2004.

Search Space Considerations

• Scope of articles in book and presentation are 2-D worlds

• Main consideration for search spaces are memory requirements and if they facilitate fast searches (using whatever algorithm we choose)

• Since all of these are basically graphs, bigger worlds will require more nodes, more edges more memory, longer searches

Page 5: Pathfinding and Movement Michael Moll September 29, 2004.

Path Optimality

Page 6: Pathfinding and Movement Michael Moll September 29, 2004.

More Considerations

• Representation must take into account way an character moves (size, etc)

• How will we create the search space?• Can they be automatically generated?• Scripting paths should use different

structure

Page 7: Pathfinding and Movement Michael Moll September 29, 2004.

Regular Grids

Page 8: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 9: Pathfinding and Movement Michael Moll September 29, 2004.

Regular Grids

NWSE Diagonals

String-PullingCatmull-Rom Spline

Page 10: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 11: Pathfinding and Movement Michael Moll September 29, 2004.

Grids as Graphs

Page 12: Pathfinding and Movement Michael Moll September 29, 2004.

Corner Graphs

• Waypoints around obstacles

Page 13: Pathfinding and Movement Michael Moll September 29, 2004.

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!

Page 14: Pathfinding and Movement Michael Moll September 29, 2004.

Corner Graphs

Page 15: Pathfinding and Movement Michael Moll September 29, 2004.

Corner Graphs

Page 16: Pathfinding and Movement Michael Moll September 29, 2004.

Waypoint Graphs

• Place nodes in middle of rooms instead of at convex corners

Page 17: Pathfinding and Movement Michael Moll September 29, 2004.

• 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

Waypoint Graphs

Page 18: Pathfinding and Movement Michael Moll September 29, 2004.

Waypoint Graphs

Page 19: Pathfinding and Movement Michael Moll September 29, 2004.

Circle-Based Waypoint Graphs

• Add radius parameter to indicate open space near waypoint

Page 20: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 21: Pathfinding and Movement Michael Moll September 29, 2004.

Space-Filling Volumes

• Use rectangles or 3-D Boxes instead of circles

Page 22: Pathfinding and Movement Michael Moll September 29, 2004.

Space-Filling Volumes

• How do we generate?– Seed and Grow– Make Grid and Merge

• Very similar to circle-based, but handles angles better

Page 23: Pathfinding and Movement Michael Moll September 29, 2004.

Navigation Meshes

• Enough with the graphs already!• Let’s try and cover walk able surfaces with

convex polygons• Character can travel between adjoining

polygons

Page 24: Pathfinding and Movement Michael Moll September 29, 2004.

Navigation Meshes

Page 25: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 26: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 27: Pathfinding and Movement Michael Moll September 29, 2004.

Problem with N-Sided Meshes

Page 28: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 29: Pathfinding and Movement Michael Moll September 29, 2004.

Further Options for Representation

• Any other ideas of what we can do to make job of path finding algorithm easier?

• Prof. Munoz has mentioned this before….

• Hierarchical Representations– Choose most suitable

scheme for given world, and break up into more manageable pieces

• Any other ideas of what we can do to make job of path finding algorithm easier?

• Prof. Munoz has mentioned this before….

• Hierarchical Representations– Choose most suitable

scheme for given world, and break up into more manageable pieces

Page 30: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 31: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 32: Pathfinding and Movement Michael Moll September 29, 2004.

Transition Table

Page 33: Pathfinding and Movement Michael Moll September 29, 2004.

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!

Page 34: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 35: Pathfinding and Movement Michael Moll September 29, 2004.

Complete Hierarchy

Page 36: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 37: Pathfinding and Movement Michael Moll September 29, 2004.

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)

Page 38: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 39: Pathfinding and Movement Michael Moll September 29, 2004.

Constructing the Hierarchy

Page 40: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 41: Pathfinding and Movement Michael Moll September 29, 2004.

Cost

• Amount of searching is limited to number of interface nodes in goal and source sets only

• Cost of searching between sets does not scale up with increases in navigation set size– Dependent on number of interface nodes

Page 42: Pathfinding and Movement Michael Moll September 29, 2004.

Applications of Navigation Set Hierarchy

• Interfacing heterogeneous navigation regions

• Navigation data on demand• Extending beyond two tiers

Page 43: Pathfinding and Movement Michael Moll September 29, 2004.

Potential Fields

• Used by Scared Little Girl in Robocode• 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

Page 44: Pathfinding and Movement Michael Moll September 29, 2004.

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”

Page 45: Pathfinding and Movement Michael Moll September 29, 2004.

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

Page 46: Pathfinding and Movement Michael Moll September 29, 2004.

Commercial Implementations

• How advanced is Half-Life 2's path finding? Is it still based around triangulations, or is it more focused on waypoints, or both... or?

• Steve Bond: I guess the best answer to this question is "A character who wants to get somewhere will find a way to get there". Half-Life 2's path finding supports swimming, flying, jumping, climbing ladders, and opening doors.

Page 47: Pathfinding and Movement Michael Moll September 29, 2004.

Commercial Implementations

• Unreal Tournament– Waypoints with pre computed paths

• Navigation Points placed throughout world– Assumes world is generally static

• Run local path finding on top of global path finding• Local path finder constants queries physics engine

to find dynamic objects

Page 48: Pathfinding and Movement Michael Moll September 29, 2004.

Commercial Implementations

• Area Awareness System– Designed for Quake 3, used in Doom 3– Does not use waypoints, instead 3-D bounded

hulls, called areas• Cost of moving from one point to another within a

hull (reachable area) is minimal• Reachability can also be determined if a hull

touches another– http://www.kbs.twi.tudelft.nl/docs/MSc/2001/W

averen_Jean-Paul_van/thesis.pdf

Page 49: Pathfinding and Movement Michael Moll September 29, 2004.

Commercial Implementations

• Half Life 2– Waypoint Based

• Call of Duty– Based off of Quake 3 AAS – Path finding handled by Conduit Engine

Page 50: Pathfinding and Movement Michael Moll September 29, 2004.

Sources• AI Game Programming Wisdom 2• H. Munoz-Avila & T. Fisher, Strategic Planning for Unreal

Tournament Bots.• First Person Shooter Architecture AI,

http://wiki.beyondunreal.com/wiki/First_Person_Shooter_AI_Architecture

• Bryan Stout, Smart Moves: Intelligent Pathfinding, http://www.gamasutra.com/features/19970801/pathfinding.htm

• JMP van Wavern, The Quake III Arena Bot, http://www.kbs.twi.tudelft.nl/docs/MSc/2001/Waveren_Jean-Paul_van/thesis.pdf

• Stefan Baert, Motion Planning Using Potential Fields, http://www.gamedev.net/reference/programming/features/motionplanning/

• John Spletzer, Lecture Notes from An Introduction to Mobile Robotics, 9/16/03