Top Banner
Individual NPC Behavior Daniel Phang & Sui Ying Teoh
63

Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Dec 13, 2015

Download

Documents

Ebony Stopper
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Individual NPC Behavior

Daniel Phang & Sui Ying Teoh

Page 2: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

NPC - Non-Player Character

• Primary application of AI in games

• Any character not controlled by playero Mobs, Monsters, Enemies

o Allies

o Noncombat or neutral units

o Environment animals

• Function to create an immersive gaming experience for the player

Page 3: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Overview

• NPC Behavior

• Coordinated Behavior

• Human-like NPCs

• Reputation Systems

• Animating NPCs

Page 4: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

NPC Behavior

Page 5: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

What is NPC Behavior?

• Actions NPCs perform (in-game behavior)o Movemento Environmental interactionso Combato Responses to game eventso Querying and storing information

• Later: animationso Movement: limb and body animationo Emotions: facial expressions, body language

Page 6: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

NPC Requirements

• Believable actions

• Realistic behavior

• Fulfill function without impeding

gameplay or other NPCs

• Minimize strain on system

• Make the game fun

Page 7: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

AI for NPC Behavior

• Static NPCs are predictable, repetitive and harder to manage

• Complex autonomous NPCs make for interesting emergent behavior and replayable games

• NPC AI must be balanced and practicalo NPC should not make the game too difficulto NPC AI needs to conserve system resourceso Unrealistic behavior and cheating is

acceptable if player does not notice

Page 8: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Scripted behaviors

• Predefined set of actions

• Good for linear environments, with

predictable events

• Bad for open or dynamic

environments, with unexpected events

• Half-Life 2 uses a lot of scripting

Page 9: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Scripts in Half-Life 2 (2:00)

Page 10: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Autonomous Behavior

• Goal-based

• NPCs are more complexo Emergent behavior based on desires, sensory

input, and proximity to objects of interest o Good response to unexpected eventso Human-like behavior: reading books,

drinking water, opening doors, etc.

• Very flexibleo Developers can create an open worldo No need to script many individual characters

• NOLF2, Far Cry 2, Assassin's Creed: Brotherhood

Page 11: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Assassin's Creed: Brotherhood

Page 12: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Autonomous Behavior

Simple implementation: Finite State Machines

Page 13: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Autonomous Behavior• Complex NPCs are more chaotic

o NOLF2: Guard leaves post to work in office

• Solution: Apply human conceptso Ownershipo Dependencyo Responsibilityo Relevanceo Priorityo Consciousnesso Expected stateo Presence of others

Page 14: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Ownership

• "Is this object mine to use?"o A guard cannot use a microscope

o A scientist cannot use a gun

• Assign ownership by grouping objects into sets belonging to specific NPCs

• What to do about public objects?o Group them into multiple overlapping sets

o Use a world set

o Don't group them at all

Page 15: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Dependency

• "Is there anything I need to do before using this object?"o NPCs use the sink after going to the toilet

• Use tightly coupled actionso Atomic, inseparable action of using toilet and sinko Less reusability in other situations

• Use dependency parameters: objects that reference others by ID

• Simple solution used in NOLF2o Disable all objects but the sink after toilet is used, and

enable all objects after sink is used

Page 16: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Responsibility

• "What is my purpose in life?"

o Guards responsible for specific areas

o Scientists never leave the lab

• Tagging objects with the character

classes allowed to use it

o Specific region tied to guards

o Only scientists can use microscopes

Page 17: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Relevance

• "How will my actions affect the player's experience?"

• Modern games fit between a simulation and a drama

• NPCs should recognize their significanceo Rabbits shouldn't be

allowed to use dramatic music when being chased

Page 18: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Priority

• "What is most important right now?"

• Aggressive > Investigative > Relaxedo Investigating a dead body vs. being on guardo NPC defending himself vs. drinking coffee

• Behavior priorities should persist until behavior is completedo Highest priority goal controls behavior

Page 19: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

State of Consciousness

• "Am I awake?"

• Unconscious NPCs have limited actionso Can snore or wake upo Should not be able to talk

• When checking bodies, NPCs should know whether the body is conscious or not

Page 20: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Expected State

• "Has anything changed?"

• Generalization of consciousnesso Ally caught in bear trap, ally is wounded, etc.o Footprints on floor

• If object is not as expected the NPCo Investigateso Returns object to its default state

• Disturbance thresholdo NPC responds when enough disturbances are

registered

Page 21: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Presence of Others

• "How will this action affect other characters?"o NPCs programmed to switch off the light

when they exit the roomo What if there are other NPCs in the room?

• NPCs should coordinate with one another

Page 22: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Coordinated Behavior

Page 23: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Coordinated Behavior

• NPCs need to be aware of each other too

• Messages NPCs need to send each other:o Split Up!o Get Out of My Way!o Get Down!o What's Going On?

• Use a blackboard to enable sharing of information among multiple NPCso Easy but effective solutiono Used in NOLF2

Page 24: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Split Up!

• NPCs crowd corridors and rooms

• Path reservationo Works best in combat scenarioso Reserve a path during planningo Path becomes more costly to other NPCso Illusion of flanking and strategy

• Maximum Occupancyo Works best in investigative scenarioso First NPC to reach a room flags it as occupiedo Additional NPCs approach room but do not entero Illusion of watching the first NPC investigate

• Blackboard coordinates path information

Page 25: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Split Up!

Page 26: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Split Up!

Page 27: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Get Out of My Way!

• NPCs get in each other's line of fire

1. Is line of fire blocked? Yes2. Is obstruction an ally? Yes3.Request ally ducks. If ally busy4.Step aside and commence firing.

• Kung Fu Attack emerges if used in close range melee attacks

Page 28: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Get Down!

• All NPCs exhibit the same behavior

o All enemies go prone at the same time

• Blackboard coordinates actions

o NPC posts AttackProne action

o Blackboard counts down ProneTime

o Other NPCs do not go prone as long as

another NPC is prone

Page 29: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

What's Going On?

• NPC is idle while ally is attacked

• NPC on patrol steps over dead body

• Apply the sensory trigger system used

to detect enemies

o Detect ally NPC's state

o Take appropriate action

Page 30: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Human-like NPCs

Page 31: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Human-like NPCs

• Games such as RPG and FPS should improve behavior to be more human-like

• We can take into account several factorso Sensory

o Memory

o Personality

o Emotions

o Physiological Stressors

Page 32: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Sensory• NPC's perception of its surroundings

o Most important: touch, sight, hearingo Less important: smell, taste

• Toucho Detecting if NPC collided with something

• Sighto A vision cone based on distanceo Affected by lighting and obstacles

• Hearingo Listening for player movements, other game

eventso Affected by proximity and environment

Page 33: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Sensory

• Smell

o Dead corpses should emit a strong stench

o Animals are more sensitive to smells

• Taste

o Humans may like or dislike certain types of

food

Page 34: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Sensory

• Games with stealth mechanicso Thief

Guards visually look for player Guards react to corpses Guards listen for environment noises &

footstepso Skyrim

Armor weight, movement speed and proximity affect movement noise

Attacking / casting spells / jumping increase noise

o Assassin's Creed Mostly visual

Page 35: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Stealth in Skyrim (1:04)

Page 36: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Memory, Personality, Emotions

• How NPCs interact with the player

• Memoryo NPC learns from interactionso Short-term vs. long-term memory

• Personalityo Happy, sarcastic, antagonistic, etc.o "Big Five": Extraversion, agreeableness,

conscientiousness, neuroticism, openness

• Emotionso The mood of NPCso Happy, sad, angry, etc.

Page 37: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Memory, Personality, Emotions

• Most useful for RPGso NPCs remember decisions player makes

o NPCs have vastly different personalities

o NPCs react to player actions

o Memorable dialogue

• In the (near) future:o More interactive dialogue, less scripted

dialogue

o Natural language processing, such as in Façade

Page 38: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Interactive NPCs in Façade (13:20)

Page 39: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Physiological Stressors

• Indicators of significant changes in the human bodyo Muscle fatigueo Paino Healtho Anxietyo Fearo Extreme temperatureso Chemicalso Hunger

Page 40: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Physiological Stressors

• Most games implement some stressors

• Sims series

o Sims have hunger, energy, fun, social,

hygiene levels

• S.T.A.L.K.E.R.

o Radiation poisoning is cured by using med-

packs, anti-radiation injections, or drinking

vodka

Page 41: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Physiological Stressors in Sims (0:50)

Page 42: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Reputation Systems

Page 43: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Reputation Systems

• Determines how NPCs react to the player

• Makes the game more believableo NPC does not smile and greet you even after you

killed their entire village

• Varies gameplayo Different dialogue options

o Different events

o Different allies / resources

o Different endings

• Can be NPC-specific / global / localized / event knowledge driven

Page 44: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

NPC-Specific Reputation• Player actions only affect specific

NPCs

• Dragon Age IIo Supporting blood mages

+ Friendship with Merril - Friendship with Fenris Other blood mages still try to kill you

o Decisions and responses to the Arishok Earning his respect means you can fight

him one-on-one Qunari still try to kill you

• Town NPCs remain unaffected

Page 45: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

DA2 Friendship with Merrill

Page 46: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

DA2 Friendship Perks

Page 47: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

DA2 Rivalry with Fenris

Page 48: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

DA2 Rivalry Perks

Page 49: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Global Reputation System• Player actions determine if 'Good' or

'Evil'

• All NPCs know what you are

• Fable IIIo Good - Angel wings, Positive responseso Bad - Bat wings, Negative responseso Neutral - Eagle wings

• Mass Effect 2o Choose sides - Paragon / Renegade

• Problemso Not quite believable - NPCs appear to be

psychico Black and white morality - Not rewarding to

be grey

Page 50: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Good Character in Fable III

Page 51: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Evil Character in Fable III

Page 52: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Reputation in Mass Effect 2

Page 53: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Grey Morality in Mass Effect 3

General Reputation

Page 54: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Localized Reputation System• Player reputation only applies within a

city or a guild

• More believableo City guards would have a central command

centero Reasonable to assume all guards share same

info

• Simpler solutiono No need for event-based system

• Skyrimo Windhelm guards do not arrest you for

crimes committed in Whiteruno Standing in Thieves Guild does not affect

standing in Dark Brotherhood

Page 55: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Localized Reputation in Skyrim

Page 56: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Event Knowledge Reputation

• More realistic: your reputation changes only if NPC has knowledge of an evento NPC is within the area when an event occurs

e.g. when an NPC dies or is attackedo NPC comes in contact with another NPC that

knows of the event

• Reputation changes aren't instantaneouso Player can keep ahead of reputation by

eliminating all witnesses of the event

Page 57: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Animating NPCs

Page 58: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Animating NPCs

• Despite good NPC behavior, NPCs still

seem artificial without smooth

animations

• In the past: animations were limited to

full-body, upper-body, or lower-body

• Now body parts should move

independently

• How do we manage independent

layers?

Page 59: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Animating NPCs

• Separate controllers for each body

part

o Overly complex

o Could lead to too many interdependencies

• Better: layered animation system

o Each layer is categorized by the body region

it affects

o Animations are prioritized by their

importance

Page 60: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Animating NPCs

• Priorities should make senseo Idle animations have priority of 0o Walks have priority of 5o Attacks have priority of 10o Reactions have priority of 20o Deaths have priority of 100

• Each category corresponds to specific body regionso If the category is upper-body, animation data

should only be for bones from the waist up

Page 61: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Animating NPCs: Implementation

• Animation controller classo Standard Template Library (STL) map which

stores animation instances, sorted by category

o Animation instances reference a resource fileo Core function PlayAnim()

Can animation be played? (based on category and priority)

Should other animations be stopped? Animations played from general to more

specific

Page 62: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

Skyrim vs Oblivion NPC Animation

(0:08)(1:46)

Page 63: Individual NPC Behavior Daniel Phang & Sui Ying Teoh.

The Ideal NPC

• Moves naturallyo Realistic movements

o Express emotions

• Acts normallyo Does what they are supposed to do

o Behaves like a human being

• Responds appropriatelyo Knows if you are a friend or an enemy

o Makes human mistakes