Navigation and AI
-
Upload
keaton-petty -
Category
Documents
-
view
25 -
download
0
description
Transcript of 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”
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, …
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
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?
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
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
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
Bidirectional search
Start simultaneously searching from both ends
Two search trees, each on average half as deep
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
Greedy best-first search
Expand to neighbor that is the closest estimated distance to the goal
Fast, easy, but may find suboptimal solutions
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”)
Demo
http://qiao.github.com/PathFinding.js/visual/
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
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
Navigation meshes
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
Pathfinding bugs
http://www.youtube.com/watch?v=lw9G-8gL5o0
NPC behavior
Large area, encompassing big parts of game design
General solution: scripting
But often, want more structure and simpler solutions
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
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
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
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/
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