Navigation and AI

24
Mark Nelson [email protected] Navigation and AI Fall 2013 www.itu.dk

description

Navigation and AI. Mark Nelson [email protected]. Movement and behaviors. In general, action in the world Some automated, some under player control Usually split into three categories Navigation, handled via navigation-specific methods Player behaviors, its own category of input/mechanic design - PowerPoint PPT Presentation

Transcript of Navigation and AI

Page 1: Navigation and AI

Mark Nelson [email protected]

Navigation and AI

Fall 2013 www.itu.dk

Page 2: Navigation and AI

Movement and behaviors

In general, action in the world Some automated, some under player control

Usually split into three categories Navigation, handled via navigation-specific methods Player behaviors, its own category of input/mechanic design NPC behaviors, core ”game AI”

Page 3: Navigation and AI

Navigation

Find paths through the world

Used by AI, but also often by humans Controlling every step is too tedious, want to get auto-routing

Want flexibility, automation, efficiency, realism, …

Page 4: Navigation and AI

Classic grid-based navigation

Square or hex tiles Entities fully occupy a tile: world is discrete

Start at tile A, end at tile B

Run a search algorithm to find a sequence of passable tiles that connect A and B

Page 5: Navigation and AI

General-purpose search algorithms

Start from a root node From each node, have candidates we can add (add a tile to

path) From each of those, have more candidates

Forms a tree

How do we traverse the tree to find a path through it?

Page 6: Navigation and AI

Breadth-first search

Expand all 1-step possibilities Then all 1-step possibilities from those If a path of length n exists, we’ll find it on the nth expansion

Guaranteed to find a solution, but may take substantial memory and time

Page 7: Navigation and AI

Depth-first search

Expand a possibility Expand a possibility from there

Repeat until we either find the goal, or hit a dead-end. Backtrack in the 2nd case.

Much fewer memory requirements, but may go off into nowhere

Page 8: Navigation and AI

Iterative deepening

Depth-first search with a depth limit Restart with a higher limit, if nothing found

Effectively does a BFS using a DFS algorithm

Less memory, but at the cost of redundant computation

Page 9: Navigation and AI

Bidirectional search

Start simultaneously searching from both ends

Two search trees, each on average half as deep

Page 10: Navigation and AI

Heuristic search

Can search faster if we have a way of estimating distance

In navigation, a minimum bound on distance is the distance if there weren’t any obstacles

Page 11: Navigation and AI

Greedy best-first search

Expand to neighbor that is the closest estimated distance to the goal

Fast, easy, but may find suboptimal solutions

Page 12: Navigation and AI

A* search

Keep track of current distance to each frontier square Expand the neighbor that has the lowest sum of:

Distance to that square Estimated remaining distance from the neighbor to goal

Guaranteed to find the best solution if the heuristic never overestimates (”admissible heuristic”)

Page 13: Navigation and AI

Demo

http://qiao.github.com/PathFinding.js/visual/

Page 14: Navigation and AI

Navigation meshes

Instead of spaces, we can be at points, with some graph connectivity

A grid can be seen as just a lattice navigation mesh

Generalize to any shape

Page 15: Navigation and AI

Navigation meshes

Large topic in itself, with some black art involved

Limit case is fully continuous movement in arbitrary spaces

Navmeshes try to look like that as much as possible, while computationally being like simple graph traversal

Page 16: Navigation and AI

Navigation meshes

Page 17: Navigation and AI

Some navmesh questions

Granularity Hierarchy Designer control vs. automated placement

Who is responsible for the non-point size of avatars/NPCs?

Standard A* search vs. specially coded routes

Page 18: Navigation and AI

Pathfinding bugs

http://www.youtube.com/watch?v=lw9G-8gL5o0

Page 19: Navigation and AI

NPC behavior

Large area, encompassing big parts of game design

General solution: scripting

But often, want more structure and simpler solutions

Page 20: Navigation and AI

Finite state machines

Simplest solution Fairly traditional, still used when lots of units w/ little

computational resources to devote

Units are in states, and situations cause them to transition

E.g. patrol, get alarmed, chase

Page 21: Navigation and AI

Behavior trees

Mix structure of FSMs with some of the more complex logic possible in general scripting

Related to reactive planning

Was introduced by Halo 2, and in a different form by Facade

Page 22: Navigation and AI

Behavior tree structure

Leaves are primitive actions, like in an FSM Non-leaf nodes have control logic

Kinds of control-logic nodes: Sequence Parallel Tests Decorators

Page 23: Navigation and AI

Further information

Three-part introduction from AiGameDev:http://aigamedev.com/open/article/behavior-trees-part1/http://aigamedev.com/open/article/behavior-trees-part2/http://aigamedev.com/open/article/behavior-trees-part3/

Page 24: Navigation and AI

Project 3

Short/small project, due 1 November

Have a square grid world, with some obstacles

Two NPCs: One tries to pathfind with A* to the other NPC, ”wins” if it hits it The other one has an FSM that tries to avoid it