250 likes | 342 Views
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?
E N D
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 Patrolling poll Player within 5 tiles Chasing
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 Game engine Player moved
Event Manager • NPCs register as listener for different events • Can register/unregister dynamically as state changes Treasure room Throne room Event manager
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 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 Manager
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 Game engine
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 What stupid horn head talk about? Hulk not hear explosion! Signal = 2.5Threshold = 1 Signal = 0.5Threshold = 1 Signal = 0.5Threshold = 0.1
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 sight, sound, smell sight, sound, smell B A B C C A sight, sound sight, sound, smell D smell One-way glass D F E sight, sound Ventilation shaft F E
Graph-based Sensing • When sense manager receives event: • Determines which room it occurs in • Determines which other rooms it may also propagate to Smell propagated to B, D, F Sight, sound propagated to A, B, D A B C Sight propagated to C Sight propagated to B, C D One-way glass Sight propagated to D F E Ventilation shaft
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? • … A B C Explosion not visible, but above threshold of hearing Explosion in line of sight D One-way glass F Not tested since room E not connected E Ventilation shaft
Event Manager • Event manager can maintain queue of events • Notify NPCs when processor cycles available • Prioritize important events Event manager Game engine Player moved
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 Event manager playerMoved (15, 73) Player within 5 tiles Chasing Compute 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 Transmits message to squad Event Manager For Squad 1 Location: (32, 14) Squad 1 Game engine Player moved to (30, 17) Event Manager For Squad 2 Location: (16, 22) Does not transmit message to squad Squad 2
Narrowcasting • Useful for messages within squad • NPC hit, changing its status • Sends message to Event Manager • Event Manager notifies rest of squad Rest of squad notified Event Manager For Squad 1 npcHit method Squad 1 Calls method in event manager