Artificial Intelligence in Game Design Map Representation and Path Finding.

30
Artificial Intelligence in Game Design Map Representation and Path Finding

Transcript of Artificial Intelligence in Game Design Map Representation and Path Finding.

Page 1: Artificial Intelligence in Game Design Map Representation and Path Finding.

Artificial Intelligence in Game Design

Map Representation and Path Finding

Page 4: Artificial Intelligence in Game Design Map Representation and Path Finding.

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:– Waypoint creation done offline (during game design)– Path planning done many times during gameplay

Page 5: Artificial Intelligence in Game Design Map Representation and Path Finding.

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

– Character must be able to directly seek all points in map from some waypoint

Page 6: Artificial Intelligence in Game Design Map Representation and Path Finding.

Defining Waypoints Manually

Page 7: Artificial Intelligence in Game Design Map Representation and Path Finding.

Defining Waypoints

• Convenient to generate waypoints automatically• Simplest case: simple 2D grid (square or hex)

– Some points impassible (water, mountains, etc.)

Page 8: Artificial Intelligence in Game Design Map Representation and Path Finding.

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.

– Usually triangular or rectangular

Page 9: Artificial Intelligence in Game Design Map Representation and Path Finding.

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.)– Make special waypoints for

door entry, exit, etc.

Page 10: Artificial Intelligence in Game Design Map Representation and Path Finding.

Triangular Mesh Generation

• Automatically generating triangular tiles that cover level– Connect some two adjacent walls to form a triangle– Continue connecting adjacent walls and/or adjacent borders– Continue until all walls are part of some triangle

Page 11: Artificial Intelligence in Game Design Map Representation and Path Finding.

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 visibility (ray tracing)

Page 13: Artificial Intelligence in Game Design Map Representation and Path Finding.

Path 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

Should seek this first

Goal:ATM

Page 14: Artificial Intelligence in Game Design Map Representation and Path Finding.

Path Creation

• Reaching goal =– Character in same tile as

goal– Character at waypoint

nearest goal

• Arrive at goal from that last waypoint

Goal

Page 15: Artificial Intelligence in Game Design Map Representation and Path Finding.

Hierarchical Paths

• Simple maps at different levels of detail– Better than single map with thousands of points– Single best solution to minimizing pathfinding costs

• Connect points on high-level maps to entrances/exits on low level maps

Page 16: Artificial Intelligence in Game Design Map Representation and Path Finding.

Hierarchical Paths

• Requires hierarchical representation of location

Under seat D001

Computer Lab

Kilcawley Center

Holy Grail

At podium

Room 301

Meshel Hall

Me

Path to room 301 exit

Path from 301 exit to Meshel Hall exit

Path from Meshel Hall exit to Kilcawley Center entrance

Path from Kilcawley Center entrance to Computer Lab entrance

Path from Computer Lab entrance to seat D001

Page 19: Artificial Intelligence in Game Design Map Representation and Path Finding.

Terrain-based 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– 8 miles of grass with ¼ mile river

= cost of 8 + 5 = 13

Page 20: Artificial Intelligence in Game Design Map Representation and Path Finding.

Other Edge Costs

• Danger – Cost of traveling through enemy territory = 5 * normal cost

– Important part of tactical movement

Page 21: Artificial Intelligence in Game Design Map Representation and Path Finding.

Other Edge Costs

• Visibility– Dark = factor of 3– Fog = factor of 2– Can also add to

danger

Long path now best

Page 22: Artificial Intelligence in Game Design Map Representation and Path Finding.

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

• Squad cost = max(individual costs)

Page 23: Artificial Intelligence in Game Design Map Representation and Path Finding.

Non-Symmetric Edge Costs

• Often harder to go one direction than another– Stairs– Jumping from one level

to lower level

• Will have different costs in each direction– Two directed edges

instead of one directed edge

– No second edge in “one way” path

4 2

1

Page 24: Artificial Intelligence in Game Design Map Representation and Path Finding.

• Some characters require time to realistically make a direction change– Part of edge cost– Separate edge from location to same location

Turning Costs

ArriveAlign

Seek

5

3

4

Page 27: Artificial Intelligence in Game Design Map Representation and Path Finding.

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

Irrelevant inflection points

Page 28: Artificial Intelligence in Game Design Map Representation and Path Finding.

Inflection Points

• Automatic creation of waypoints on arbitrary racing track

Page 29: Artificial Intelligence in Game Design Map Representation and Path Finding.

Path Smoothing

• Problem: Grid-based floor tiles with waypoints at center– Jagged” paths– Too many unnecessary turns– Better to create path using non adjacent nodes

Page 30: Artificial Intelligence in Game Design Map Representation and Path Finding.

Path Smoothing

• Recursive algorithm:– Draw line between start and goal– Stop at obstacle– Continue