pathfinding - part 3: beyond the basics

52
INTERACTIVE OBJECTS IN GAMING APPLICATIONS Basic principles and practical scenarios in Unity June 2013 Stavros Vassos Sapienza University of Rome, DIAG, Italy [email protected]

Upload: stavros-vassos

Post on 26-Jun-2015

850 views

Category:

Education


1 download

DESCRIPTION

These slides are part of a course about interactive objects in games. The lectures cover some of the most widely used methodologies that allow smart objects and non-player characters (NPCs) to exhibit autonomy and flexible behavior through various forms of decision making, including techniques for pathfinding, reactive behavior through automata and processes, and goal-oriented action planning. More information can be found here: http://tinyurl.com/sv-intobj-2013

TRANSCRIPT

Page 1: Pathfinding - Part 3: Beyond the basics

INTERACTIVE OBJECTS IN

GAMING APPLICATIONS

Basic principles and practical scenarios in Unity

June 2013 Stavros Vassos Sapienza University of Rome, DIAG, Italy [email protected]

Page 2: Pathfinding - Part 3: Beyond the basics

Interactive objects in games 2

Pathfinding

Part 1: A* heuristic search on a grid

Part 2: Examples in Unity

Part 3: Beyond the basics

Action-based decision making

AI Architectures

Page 3: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond the basics 3

Many neat tricks for efficient/nice pathfinding

Alternative game-world representations

Beyond A*

Better heuristics

Page 4: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond the basics 4

Many neat tricks for efficient/nice pathfinding

Alternative game-world representations

Beyond A*

Better heuristics

Page 5: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 5

A* works the same in a graph as in a grid

Graphs nodes correspond to points in the 2D/3D space

We can still use the same heuristics

Manhattan, Chebyshev, Euclidean

Page 6: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 6

A* works the same in a graph as in a grid

Graphs nodes correspond to points in the 2D/3D space

We can still use the same heuristics

Manhattan, Chebyshev, Euclidean

But we need to

generate these

graphs in an

automated way!

Page 7: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 7

Many types of graphs have been studied in video-

games as well as in robotics

Waypoint graphs

Circle-based waypoint graphs

Visibility graphs

Navigation mesh graphs

Probabilistic road maps

Page 8: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 8

Many types of graphs have been studied in video-

games as well as in robotics

Waypoint graphs

Circle-based waypoint graphs

Visibility graphs

Navigation mesh graphs

Probabilistic road maps

Nice description on Amit’s A* pages, next

Page 9: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 9

Visibility graph

Connected obstacle corners

Navmesh graph

Connected walkable areas

Page 10: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 10

Visibility graph

Connected obstacle corners

Navmesh graph

Connected walkable areas

Visibility graph:

Often contains too

many edges

Page 11: Pathfinding - Part 3: Beyond the basics

Pathfinding: From grids to graphs 11

Visibility graph

Connected obstacle corners

Navmesh graph

Connected walkable areas

Navmesh graph:

Several ways to

map to a graph

Page 12: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 12

Navmesh graph

Area decomposed in polygons

One or more graph nodes per polygon

Polygon center movement

One node at the

center of each polygon

Nodes connected if

they are in adjacent

polygons

Page 13: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 13

Navmesh graph

Area decomposed in polygons

One or more graph nodes per polygon

Polygon edge movement

One graph node at the

center of each edge

between adjacent

polygons

Don’t have to go to the

center of a polygon

Page 14: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 14

Navmesh graph

Area decomposed in polygons

One or more graph nodes per polygon

Polygon vertex movement

Graph nodes and edges

at each as the polygons

Helpful for moving

around an obstacle,

following its edges

Page 15: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 15

Navmesh graph

Area decomposed in polygons

One or more graph nodes per polygon

Pick your own hybrid

combination!

Here: graph nodes both

at nodes of polygons

and the middle

of edges of polygons

Page 16: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 16

Navmesh graph

Widely used in video games!

Supported natively in Unity Pro after version 4

A lot of passionate supporters :)

Page 17: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 17

“Fixing pathfinding once and forall” by Paul Tozour

(2008) at www.ai-blog.net

Pathfinding on waypoint graphs vs navmesh graphs

1. Some graphs require too many waypoints

Page 18: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 18

“Fixing pathfinding once and forall” by Paul Tozour

(2008) at www.ai-blog.net

Pathfinding on waypoint graphs vs navmesh graphs

2. More difficult to make “smooth” realistic paths

Page 19: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 19

“Fixing pathfinding once and forall” by Paul Tozour

(2008) at www.ai-blog.net

Pathfinding on waypoint graphs vs navmesh graphs

3. More difficult to handle dynamic obstacle avoidance

Page 20: Pathfinding - Part 3: Beyond the basics

Pathfinding: Navmesh graphs 20

“Fixing pathfinding once and forall” by Paul Tozour

(2008) at www.ai-blog.net

Pathfinding on waypoint graphs vs navmesh graphs

Other interesting observations in the article

Page 21: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond the basics 21

Many neat tricks for efficient/nice pathfinding

Alternative game-world representations

Beyond A*

Better heuristics

Page 22: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 22

Incremental versions of A*

Real-time/Any-time versions of A*

Hierarchical versions of A*

Any-angle pathfinding

Diverse character pathfinding

Cooperative pathfinding

Page 23: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 23

Incremental versions of A*

Real-time/Any-time versions of A*

Hierarchical versions of A*

Any-angle pathfinding

Diverse character pathfinding

Cooperative pathfinding

Nice article by Alex Nash at AiGameDev.com, next

Page 24: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 24

Any-angle pathfinding

Theta*

Combining visibility graphs and the power of A* on grids

Simple extension based on A*

Here: 8-connected nodes at the corners of each cell

Page 25: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 25

Finding better/nicer paths vs post-processing paths

Page 26: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 26

Finding better/nicer paths vs post-processing paths

Manhattan distance

heuristic

Chebyshev distance

heuristic

Page 27: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 27

Finding better/nicer paths vs post-processing paths

Manhattan distance

heuristic

Chebyshev distance

heuristic

Slower, but easier

to improve

Faster, but more

difficult to improve

Page 28: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 28

Any-angle pathfinding with Theta*

Very similar to A*

Search from the start node

Open list of nodes to visit

Closed list of visited nodes

Expand a node by looking

into neighbors

Compute and store f(s’) for each of the neighbors of

expanded node s: f(s’) = g(s’) + h(s’)

Page 29: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 29

Any-angle pathfinding with Theta*

Very similar to A*

Search from the start node

Open list of nodes to visit

Closed list of visited nodes

Expand a node by looking

into neighbors

Compute and store f(s’) for each of the neighbors of

expanded node s: f(s’) = g(s’) + h(s’)

But, do a trick in computing g(s’) and the parent of s’!

Page 30: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 30

Any-angle pathfinding with Theta*

Expand node s

Look into neighbors of s, e.g., node s’

Consider two cases when computing g(s’)

Page 31: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 31

Any-angle pathfinding with Theta*

Expand node s

Look into neighbors of s, e.g., node s’

Consider two cases when computing g(s’)

Option 1: g(s’) = g(s) + c(s,s’)

Page 32: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 32

Any-angle pathfinding with Theta*

Expand node s

Look into neighbors of s, e.g., node s’

Consider two cases when computing g(s’)

Option 1: g(s’) = g(s) + c(s,s’)

Option 2: g(s’) = g(p) + c(p,s’),

where p is the parent of s!

Page 33: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 33

Any-angle pathfinding with Theta*

Expand node s

Look into neighbors of s, e.g., node s’

Consider two cases when computing g(s’)

Option 1: g(s’) = g(s) + c(s,s’)

Option 2: g(s’) = g(p) + c(p,s’),

where p is the parent of s!

If the Option 2 is better also

update the parent!

Page 34: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 34

Any-angle pathfinding with Theta*

Essentially remove unnecessary grid-like steps, using

visibility information

Simplifying and smoothing as you go!

Page 35: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 35

Any-angle pathfinding with Theta*

Essentially remove unnecessary grid-like steps, using

visibility information

Simplifying and smoothing as you go!

Page 36: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond A* 36

Incremental versions of A*

Real-time/Any-time versions of A*

Hierarchical versions of A*

Any-angle pathfinding

Diverse character pathfinding

Cooperative pathfinding

Nice resources available!

Page 37: Pathfinding - Part 3: Beyond the basics

Pathfinding: beyond A* 37

AAAI 2008 tutorial on path planning

Part 1: Advances in Path Planning by Sven Koenig

http://webdocs.cs.ualberta.ca/~nathanst/aaai_tut1.pdf

Any-angle pathfinding

Field D*, Theta*

Incremental versions of A*

FSA*, AA*, LPA*, MTAA*, D*Lite

Real-time versions of A*

LRTA*, RTAA*

Page 38: Pathfinding - Part 3: Beyond the basics

Pathfinding: beyond A* 38

AAAI 2008 tutorial on path planning

Part 2: Abstraction in Pathfinding by Nathan Sturtevant

http://webdocs.cs.ualberta.ca/~nathanst/aaai_tut2.pdf

http://webdocs.cs.ualberta.ca/~nathanst/pathfinding.html

Abstraction for minimizing memory

Used in BioWare’s Dragon Age

Generalized Cooperative pathfinding

CA*, WHCA*, PRA*, CPRA*

Page 39: Pathfinding - Part 3: Beyond the basics

Pathfinding: beyond A* 39

Beyond A*: Speeding up pathfinding through

hierarchical abstraction by Daniel Harabor

http://harablog.files.wordpress.com/2009/06/beyonda

star.pdf

Hierarchical pathfinding

HPA*

Dealing with diversity

HAA*

Beyond grids

Probabilistic

Road Maps

Page 40: Pathfinding - Part 3: Beyond the basics

Pathfinding: beyond A* 40

AAAI 2008 tutorial on path planning

Part 3: Map Representations & Geometric Path Planning

by Michael Buro

http://webdocs.cs.ualberta.ca/

~nathanst/aaai_tut3.pdf

Polygon-based

Free space decompositions

TA*: Triangulation A*

TRA*: Triangulation reductions A*

Page 41: Pathfinding - Part 3: Beyond the basics

Pathfinding: Beyond the basics 41

Many neat tricks for efficient/nice pathfinding

Alternative game-world representations

Beyond A*

Better heuristics

Page 42: Pathfinding - Part 3: Beyond the basics

Pathfinding: Better heuristics 42

True distance memory based heuristics (TDHs)

Main idea based on precomputing useful information

Store true distance between selected pairs of nodes

Use these to calculate admissible estimates for any pair

Different variations

How to chose the initial pairs to pre-compute

How to calculate heuristic values from pre-computed

pairs

Recent IJCAI-09 paper and SOCS-10 paper

Page 43: Pathfinding - Part 3: Beyond the basics

Pathfinding: Better heuristics 43

Differential heuristic

Pick a set of “canonical” nodes

Compute true distance between every node and the

canonical nodes

For dist(a,b) look into all canonical nodes c and take as

estimate the max value of |dist(a,c)-dist(b,c)|

Page 44: Pathfinding - Part 3: Beyond the basics

Pathfinding: Better heuristics 44

Differential heuristic

Pick a set of “canonical” nodes

Compute true distance between every node and the

canonical nodes

For dist(a,b) look into all canonical nodes c and take as

estimate the max value of |dist(a,c)-dist(b,c)|

Admissible!

Intuition: think of just one canonical state c

dist(a,b)+dist(b,c) has to be greater or equal than dist(a,c)

otherwise this would have been stored as a shorter route

The max out of many canonical states is a better lowerbound

a b

c

Page 45: Pathfinding - Part 3: Beyond the basics

Pathfinding: Better heuristics 45

Canonical heuristic

Pick a set of “canonical” nodes

Compute true distance between the canonical nodes

Compute true distance between every node and the m

closest canonical nodes

For dist(a,b) look into all pairs of m canonical nodes c1

close to a and m canonical nodes c2 close to b, and

take as estimate the max value of

|dist(c1,c2) - dist(a,c1) - dist(b,c2)|

Page 46: Pathfinding - Part 3: Beyond the basics

Pathfinding: Better heuristics 46

Border heuristic and portal-based heuristic

Domain is partitioned in regions

Borders between regions

Portals connect regions

Store true distance

between pairs of portals

Portal-based search

that breaks pathfinding

into sub-problems

Page 47: Pathfinding - Part 3: Beyond the basics

Pathfinding: Compress Path Databases 47

Another neat idea in a recent AIIDE-11 paper

Ultra-Fast Optimal Pathfinding without Runtime Search

Page 48: Pathfinding - Part 3: Beyond the basics

Pathfinding: Compress Path Databases 48

Another neat idea in a recent AIIDE-11 paper

Ultra-Fast Optimal Pathfinding without Runtime Search

Pre-computing and store all paths!

Compress Path Databases that bring the data to

manageable size

Compared to A* runtime speedup reaches two orders

of magnitude

It has been tested over maps of Baldur’s Gate

Page 49: Pathfinding - Part 3: Beyond the basics

Pathfinding: Compress Path Databases 49

“Path coherence”

The shortest paths from a current node to any target in

a remote area share a common first move

Think of going from Rome to a destination in any city in

western Europe

Most probably all shortest paths from a specific

starting point to any of these destinations have to pass

through some fixed landmarks, e.g., a major intersection

CPDs store this information for every node in the graph

Page 50: Pathfinding - Part 3: Beyond the basics

Pathfinding: Compress Path Databases 50

CPDs compress this information for every node in

the graph using boxes of destinations that can be

“directed” in the same way

1. Starting from here

2. Going to here

Page 51: Pathfinding - Part 3: Beyond the basics

Pathfinding: Compress Path Databases 51

CPDs compress this information for every node in

the graph using boxes of destinations that can be

“directed” in the same way

1. Starting from here

2. Going to here

3. You need to go NE!

Page 52: Pathfinding - Part 3: Beyond the basics

Pathfinding: Compress Path Databases 52

CPDs compress this information for every node in

the graph using boxes of destinations that can be

“directed” in the same way

One starting node

For all possible destinations

Compute the next move that you

needs to be performed

Make this map

Store it by compressing

regions