Artificial Intelligence in
Game Design
Path Creation
Strategy
Path Planning
Movement
“Where to move to” “How to get there” “Get there”
Current location
Waypoints
• Path = graph structure
• Vertices = waypoints on path
• Edges between waypoints directly reachable from one
another
Waypoints and Costs
• Goals:
– Provide waypoints that let characters reach all
locations on level
• Can SEEK any location from some waypoint
– Minimize number of waypoints
• Cost of path planning = O(number of waypoints)2
• Key idea:
Defining Waypoints
• Defining waypoints manually
– Usually at points where direction change necessary
• Corners • Intersections • Doors
– Character must be able to directly seek waypoint from any adjacent waypoint
Defining Waypoints
• Convenient to generate waypoints automatically
• Simplest case: simple 2D grid (square or hex)
Defining Waypoints Automatically
• Can often use floor tiles
– Used by level designer to create level
– Used to define visibility,
lighting areas, where sounds can be heard, etc.
Defining Waypoints Automatically
• One waypoint per tile
– Usually in center
• Link waypoints in adjacent
tiles
• May still need to tweak
manually
– Make sure all points directly reachable from a waypoint – Add strategic waypoints
(cover, shadow, etc.)
Triangular Mesh Generation
• Automatically generating triangular tiles that cover level
– Connect some two adjacent walls to form a triangle
Waypoint Cleanup
• Can automatically
remove some “redundant”
waypoints
– Not an endpoint
(degree > 1)
– All adjacent points can
directly reach each
other without using
that waypoint
– Often based on
Path Creation
• Path = list of adjacent
waypoints
• Move along path using
FollowPath
steering
– Seek “close enough” to next path waypoint Desired path 73 27 21 45Path Creation
• Initial waypoint =
– Waypoint in same tile as character
– Closest waypoint to character
• May need to test each
– Avoid going backward initially – Less of a problem with small
tiles
•
Seek
that first waypoint
Path Creation
• Reaching goal =
– Character in same tile as goal
– Character at waypoint nearest goal
•
Arrive
at goal from that
last waypoint
Hierarchical Paths
• Simple maps at different levels of detail
– Better than single map with thousands of points – Single best solution to minimizing pathfinding costs
Hierarchical Paths
• Requires hierarchical representation of location
Path Planning
• May have several
possible paths from
current location to goal
• Need to find “best” path
– Otherwise character does not look intelligent!
Goal
Good path
Edge Costs
• “Best” path defined
by edge costs
Terrainbased Costs
• Can base cost on terrain type
– Grass = 1 – Desert = 2 – Forest = 3 – River = 20
• Often multiply by edge
distance
– 5 miles of desert = cost of 10
Other Edge Costs
•
Danger
– Cost of traveling through enemy territory = 5 * normal cost
Other Edge Costs
•
Visibility
– Dark = factor of 3
– Fog = factor of 2
– Can also add to danger
Character Edge Costs
• Different characters may have different edge costs
– Grass = 2 – Desert = 2 – Forest = 10 – River = 30
– Grass = 1 – Desert = 3 – Forest = 2 – River = 10
NonSymmetric Edge Costs
• Some characters require time to realistically make a
direction change
– Part of edge cost
– Separate edge from location to same location
Turning Costs
Arrive Align
Seek
5 3
Inflection Points
• Waypoints often near convex corners
– Shortest path in wide areas
– Better than putting waypoint in center of area
Path given by floor tiles
Inflection Points
• Put waypoint at each convex corner • Move out some safeRadius from corner
• Connect waypoints visible from one another
Inflection Points
• Potential problem: “jagged” areas could create too many waypoints • Solution: Only add waypoints for obstacles between critical areas
(such as doors)
– Recursively add waypoints until critical areas connected
Inflection Points
• Automatic creation of
waypoints on
Path Smoothing
• Problem: Gridbased floor tiles with waypoints at center
– Jagged” paths
– Too many unnecessary turns
Path Smoothing
• Recursive algorithm:
– Draw line between start and goal – Stop at obstacle