individual npc behavior daniel phang & sui ying teoh

Post on 13-Dec-2015

223 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

Overview

• NPC Behavior

• Coordinated Behavior

• Human-like NPCs

• Reputation Systems

• Animating NPCs

NPC Behavior

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

NPC Requirements

• Believable actions

• Realistic behavior

• Fulfill function without impeding

gameplay or other NPCs

• Minimize strain on system

• Make the game fun

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

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

Scripts in Half-Life 2 (2:00)

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

Assassin's Creed: Brotherhood

Autonomous Behavior

Simple implementation: Finite State Machines

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

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

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

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

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

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

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

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

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

Coordinated Behavior

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

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

Split Up!

Split Up!

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

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

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

Human-like NPCs

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

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

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

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

Stealth in Skyrim (1:04)

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.

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

Interactive NPCs in Façade (13:20)

Physiological Stressors

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

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

Physiological Stressors in Sims (0:50)

Reputation Systems

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

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

DA2 Friendship with Merrill

DA2 Friendship Perks

DA2 Rivalry with Fenris

DA2 Rivalry Perks

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

Good Character in Fable III

Evil Character in Fable III

Reputation in Mass Effect 2

Grey Morality in Mass Effect 3

General Reputation

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

Localized Reputation in Skyrim

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

Animating NPCs

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?

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

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

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

Skyrim vs Oblivion NPC Animation

(0:08)(1:46)

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

top related