View
219
Download
1
Category
Preview:
Citation preview
Artificial Intelligence in Game Design
Event and Sense Management
Event Management
• Dozens/hundreds of NPCs• Hundreds of possible events that may affect them
– Player visible – Explosion heard– Collision with wall– …
• How to efficiently notify NPCs affected by events?– “notify” = run appropriate code related to event
• Shoot at player
• Move towards sound
• Move away from wall…
Created by game engine
Polling
• Game engine maintains list of values related to game state• Each time frame, cycle through active NPCs
– Examine values that would affect NPC(transitions from current state of NPC)
• Very inefficient if many NPCs/possible events
Variable State
… …
playerLocation (15, 73)
Patrolling
Chasing
Player within 5 tilespoll
Event Manager
• Maintains list of “listener” NPCs for each event type– When game engine changes state, notifies event manager– Event manager calls code in all NPCs listening for that event
Event manager
Player moved
Orc1
Orc3
Explosion
Orc2
Orc3
Game enginePlayer moved
Event Manager
• NPCs register as listener for different events– Can register/unregister dynamically as state changes
Treasure room
Throne room
Event manager
Player in throne room
Orc1
Orc3
Player in treasure room
Orc2
Orc3
Orc1
Sense Management
• Question: When should character know about event?– Told by event manager/react to message from event handler
• Answer: If it would be physically plausible for the character to have sensed the event
Hears explosion
Too far away
Inside soundproofed building
Sight
• Simple approach: distance based– Notify NPC when player < d units away
• Many games much more sophisticated!• Goal: Use “stealth” to avoid or ambush enemies
– Splinter Cell– Ghost Recon– …
Sight
• Raycasting– Compute what is visible from NPC point of view– Same code used to determine what is visible from camera POV
to render game each frame
Sight
• Sight Cone– Visual perception defined by cone in direction NPC is facing
– Usually 120 degrees vertical, 220 degrees horizontal
– Only notify NPC about events within that cone
Sight
• Darkness– Idea: Player should be able to hide in shadows– Game engine computes light level at each point when rendering – Player in area with light level < threshold
NPC not notified about player
Sight
• Camouflage– Idea: Characters against background of same color are less visible– Project rays from NPC past player to find object directly behind them– If color of that object ≈ color of player, do not notify NPC
Hearing
• Transmitted in all directions– Always heard unless character in soundproofed area
• Attenuates with distance – Character will not hear once below threshold of hearing
• Slower than light– Characters at great distance will not hear immediately
Will hear 3 seconds later
1 km
Touch
• If player “bumps” NPC, NPC should perceive player immediately
• Can use collision detection built into game engine
Smell
• Animals can detect scent of other animals– Can follow scent in direction of increasing signal to player (like
smart terrain)– Greater time spent in one area greater scent level– Depends on wind direction
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
2 3 4 6 5 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 3 2 1
1 2 3 2 1
1 2 1
1
wind
Sense Manager
• Acts like event manager for sensory input– Characters register with sense manager– Provide sensory information:
• Position• Orientation (for sight)• Sense information (including thresholds)
Sense ManagerPosition (32, 18)
Orientation 30 degrees
Sight true
Hearing Thresh = 1.0
Position (16, 25)
Orientation 160 degrees
Sight false
Hearing Thresh = 0.1
Position (18, 22)
Orientation 310 degrees
Sight true
Hearing Thresh = 1.0
Sense Manager
• Events from game engine include sensory data– Location– Intensity at source– Medium (sight, sound, etc.)
• Sense manager determines which NPCs to notify based on their properties, and physics of game
Sense Manager
Gameengine Location (35, 10)
Intensity 100
Medium sound
Attenuation-Based Sensing
• Can implement all senses as attenuation for simplicity
– Signal received by character = intensity at event source distance from event source
– Character notified if signal strength ≥ threshold for that sense
– Works best in worlds consisting of open areas
Signal = 2.5Threshold = 1 Signal = 0.5
Threshold = 1
Signal = 0.5Threshold = 0.1
What stupid horn head talk about? Hulk not hear explosion!
Attenuation-Based Sensing
• Can apply to sight as well– Intensity at source based on size of object
– Shadow decreases intensity at source • Proportional to light level
– Camouflage decreases intensity at source• Proportional to difference from background
– Still need checks for sight cone, visibility
Graph-based Sensing
• Simplifies sensing in “dungeon” worlds with many rooms• Graph defines how signals propagate between rooms
– Nodes = rooms– Edges = signals that travel from one room to another
One-way glass
Ventilation shaft
A B C
D
EF
A
F
B
C
D
E
sight, sound
sight, sound, smell
smell
sight, sound, smell
sight, sound, smell
sight, sound
Graph-based Sensing
• When sense manager receives event:– Determines which room it occurs in– Determines which other rooms it may also propagate to
One-way glass
Ventilation shaft
A B C
D
EF
Sight, sound propagated to A, B, D
Smell propagated to B, D, F
Sight propagated to B, C Sight propagated
to D
Sight propagated to C
Graph-based Sensing
• Sense manager then verifies that NPCs in rooms can actually perceive event – Are characters actually in line of sight?– Do sounds attenuate below threshold of hearing?– …
One-way glass
Ventilation shaft
A B C
D
EF
Explosion in line of sight
Explosion not visible, but above threshold of hearing
Not tested since room E not connected
Event Manager
• Event manager can maintain queue of events– Notify NPCs when processor cycles available– Prioritize important events
Event manager
Player moved
Orc1
Orc3
Explosion
Orc2
Orc3
Gameengine
Player moved
Events
Player moved
Explosion
Broadcasting
• Event manager notifies all registered NPCs about event• Each NPC must decide in their code whether event
applies to them– Simple to implement, but may not be efficient
Patrolling
Chasing
Player within 5 tilesplayerMoved (15, 73) Event manager
Player moved
Orc1
Orc3Compute whether (15, 73) is within 5 tiles of current position
Narrowcasting
• Multiple event handlers instead of one– Each handles related subset of NPCs
– Determines whether message passed on to its NPCs
– More efficient since fewer messages sent overall
Squad 1
Squad 2
Event ManagerFor Squad 1
Location: (32, 14)
Event ManagerFor Squad 2
Location: (16, 22)
Gameengine
Player moved to (30, 17)
Transmits message to squad
Does not transmit message to squad
Narrowcasting
• Useful for messages within squad– NPC hit, changing its status
– Sends message to Event Manager
– Event Manager notifies rest of squad
Squad 1
Event ManagerFor Squad 1
npcHit method
Calls method in event manager
Rest of squad notified
Recommended