lecture 22 - cornell university

38
gamedesigninitiative at cornell university the Character AI: Sensing & Perception Lecture 22

Upload: others

Post on 29-Apr-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Character AI: Sensing & Perception

Lecture 22

Page 2: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Take Away for Today

�  Sensing as the primary bottleneck �  Why is sensing so problematic? �  What types of things can we do to improve it?

�  Optimized sense computation �  Can we improve sense computation performance? �  Can we share sensing between NPCs?

�  Sense event matching �  What are events and how are they represented? �  What is the advantage of an event system?

Sensing & Perception 2

Page 3: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Sense: �  Perceive the world �  Reading the game state �  Example: enemy near?

�  Think: �  Choose an action �  Often merged with sense �  Example: fight or flee

�  Act: �  Update the state �  Simple and fast �  Example: reduce health

Sensing & Perception 3

Review: Sense-Think-Act

?

Page 4: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Sensing may be slow! �  Consider all objects

�  Example: morale �  n knights, n skeletons �  Knights fear skeletons �  Proportional to # seen

�  Count skeletons in view �  O(n) to count skeletons �  O(n2) for all units

Recall: Sensing Performance

Time per tick

3 units 2 units 1 unit

Sensing & Perception 4

Page 5: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Sensing may be slow! �  Consider all objects

�  Example: morale �  n knights, n skeletons �  Knights fear skeletons �  Proportional to # seen

�  Count skeletons in view �  O(n) to count skeletons �  O(n2) for all units

Recall: Sensing Performance

Time per tick

3 units 2 units 1 unit

Sensing & Perception 5

Page 6: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Idea taken from databases �  Unordered set of information �  Combine into single value �  Used in statistical analysis �  Examples: sum, avg, mode

�  Decomposable Aggregates �  Split the set up into subsets �  Aggregate on each subset �  Combine values from subsets �  Only for some aggregates

6

10

5

7

9

7

3

9

Sensing & Perception 6

Aggregation

avg = 8 (16,2)

avg = 6 (12,2)

avg = 8 (16,2)

avg = 6 (12,2)

avg = 7 (28,4)

avg = 7 (28,4)

avg = 7 (56,8)

Page 7: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Idea taken from databases �  Unordered set of information �  Combine into single value �  Used in statistical analysis �  Examples: sum, avg, mode

�  Decomposable Aggregates �  Split the set up into subsets �  Aggregate on each subset �  Combine values from subsets �  Only for some aggregates

6

10

5

7

9

7

3

9

Sensing & Perception 7

Aggregation

avg = 8 (16,2)

avg = 6 (12,2)

avg = 8 (16,2)

avg = 6 (12,2)

avg = 7 (28,4)

avg = 7 (28,4)

avg = 7 (56,8)

Allows for fast

parallel computation

Page 8: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

AI and Aggregation Trees

Number of Allies

Number of Enemies

Threat Ratio

My Health Proximity to Leader

Strength of Allies

Strength of Enemies

Allied Strength Enemy Strength

My Morale

Retreat %

Proximity to Base

Urgency

Slide courtesy of Dave Mark

Sensing & Perception 8

Page 9: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

AI and Aggregation Trees

Number of Allies

Number of Enemies

Threat Ratio

My Health Proximity to Leader

Strength of Allies

Strength of Enemies

Allied Strength Enemy Strength

My Morale

Retreat %

Proximity to Base

Urgency

Slide courtesy of Dave Mark

Do all “sides” ���at once using ���key-value pairs

Sensing & Perception 9

Map-Reduce Pipeline

Page 10: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Influence Maps: Pathfinding and AI

A

B

Slide courtesy of Dave Mark

Sensing & Perception 10

Page 11: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Use the pathfinding grid �  Track movement in square �  Track if friend or foe

�  Keep count as a queue �  Count is sum of queue �  Allows us to “time out” �  Otherwise, marked forever

�  Use queue as a predictor �  Look at rate of change �  Also valuable for AI

Sensing & Perception 11

Implementing Influence Maps

A B 1 1 1 1

1 0 0 1

Sensing is at grid, not NPC

Page 12: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Advantages of Influence Maps

A

B

Slide courtesy of Dave Mark

Sensing & Perception 12

Influence data reflects changes

Page 13: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Advantages of Influence Maps

A

B

Slide courtesy of Dave Mark

Sensing & Perception 13

Add a priori assumptions

Page 14: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing: Perception Groups

�  Vision: limited field of view �  Gives exact object location, information �  Limited by obstacles and range �  Little information (motion) at periphery

�  Sound: omni-directional �  Gives direction & distances �  Requires you track the “sounds” actions make

�  Smell: omni-directional �  No direction or distance; proximity only �  Requires you track the “smells” actions make

Sensing & Perception 14

Page 15: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 15

Sensing: Line-of-Sight

Page 16: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 16

Sensing: Line-of-Sight

Page 17: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

3D Line-of-Sight: Ray Casting

Sensing & Perception 17

Page 18: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

3D Line-of-Sight: Ray Casting

18 Sensing & Perception

Page 19: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

3D Line-of-Sight: Ray Casting

Sensing & Perception 19

Page 20: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Event: encoded sense data �  Tagged with sense type �  Information self-contained

�  Object with methods �  Class is sense type

�  Sensing is event matching �  Each event has a type �  NPCs “register” for a type �  Send NPC registered events �  Check if event is relevant

Sensing & Perception 20

Sense Events

Event: CharacterExposed!!

boolean isSeen(NPC guard); float distanceTo(NPC guard); Vector moveDirection();

Pre-aggregated ���information

Page 21: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 21

Sense Event Matching

Event Handler

Register events of interest

Gam

e Loop

sound

sight sound

sound smell

Page 22: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 22

Sense Event Matching

Event Handler

Notify of any matching events

Check for any matching events

Gam

e Loop

Page 23: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 23

Sense Event Matching

Event Handler

Notify of any matching events

Check for any matching events

Gam

e Loop

Advantage: Sensing is Global, Not Local

Page 24: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Lightweight

Sensing & Perception 24

Representing Events

Heavyweight

Memory

Player

CharacterExposed

Memory

Player

CharacterExposed

Reference to player

Copy of player

Page 25: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Lightweight class Event {� Player ref;� Event(Player p) {� ref = p;� }�}

�  Advantages �  Fast to create event �  No additional memory

Sensing & Perception 25

Representing Events

Heavyweight class Event {�

Player ref;� Event(Player p) {� ref = p.copy();� }�}

�  Advantages �  Stores past events �  Can be communicated

Page 26: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Complex Query System

�  NPC Hashtable �  Event types are keys �  Values are lists of NPCs!�  Say NPC subscribes to e

�  Each update cycle… �  Generate all of the events �  Get NPCs for each event �  Send those events to NPC �  Process NPCs normally

Sensing & Perception 26

Simple Pub/Sub Architecture

Pub/Sub System

Gam

e Loop

tag1

tag2

tag1, tag3

tag4

Page 27: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

NPC Behavior

Complex Query System

Sensing & Perception 27

Simple Pub/Sub Architecture

Pub/Sub System

Gam

e Loop

tag1

tag2

tag1, tag3

tag4

Page 28: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Restrict to nearby NPCs �  Have detection range

�  Limits events sensed

�  Easy to combine with event matching system

� Works in both directions �  Nimbus: “can see” radius

�  Aura: “can be seen” radius

�  Area of interest management

Sensing & Perception 28

Spatial Optimizations

Page 29: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Case Study: Thief Series

Sensing & Perception 29

Page 30: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

30 Sensing & Perception

Page 31: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 31

Line-of-Sight in Thief

Focused View

Long Distance

Short Distance Peripheral

Vision

Motion Detection

Page 32: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  “Easier” than vision �  Primarily distance-based �  Decays probabilistically �  Tag with level of interest

�  Sounds can be blocked �  Not same as line-of-sight �  Use alternate level map �  Or tag your visible map

�  Not physically realistic �  Echoes? Reflections

Sensing & Perception 32

Sounds in Thief

Page 33: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

�  Sounds are general purpose �  Resuable framework �  Code is lightweight �  Encodes other senses

�  Example: Smell �  Treated as “pseudo-sound” �  Generate like any sound

�  Again, ignores other factors �  Wind direction �  Masking smells

Sensing & Perception 33

Sounds in Thief

* sniff *

* sniff *

Page 34: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Lightweight class Event {� Player ref;� Event(Player p) {� ref = p;� }�}

�  Advantages �  Fast to create event �  No additional memory

Sensing & Perception 34

Representing Events

Heavyweight class Event {�

Player ref;� Event(Player p) {� ref = p.copy();� }�}

�  Advantages �  Stores past events �  Can be communicated

Page 35: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 35

Communicating Senses

First Hand LOS

Sight & Sound Second Hand Sight & Sound

First Hand LOS

Sight & Sound

?

Page 36: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Sensing & Perception 36

Alertness: Active Senses

First Hand LOS

Sight & Sound Second Hand Sight & Sound

First Hand LOS

Sight & Sound

High Alert Medium Alert

High Alert

First Hand Sound

Page 37: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Lighting Movement Exposure

Visibility

Viewcone

Sound System

Sound Queue

Non-specific Spatial Events

Listen Look

Sense Pulse Receiver

Ramp Up Delay

Cool-down Capacitor

Inter-Agent Communication

Inter-Agent Observation

Viewcone Selector

Position

Game Mechanics and Configuration

Sense Links 37

Thief: Sense Events and Aggregation

Page 38: Lecture 22 - Cornell University

gamedesigninitiativeat cornell university

the

Summary

�  Sensing is the most expensive part of AI �  Each character “looks” at every object in game �  Often leads to O(n2) behavior (bad!)

�  Can optimize sense gathering �  Aggregation is amenable to parallelization �  Can piggyback some data onto pathfinding

�  Event matching inverts the sensing problem �  Creation of sense makes a data event �  Forward event to “relevant” NPCs

Sensing & Perception 38