Individual NPC Behavior

advertisement
Individual NPC Behavior
Daniel Phang & Sui Ying Teoh
NPC - Non-Player Character
•
•
Primary application of AI in games
Any character not controlled by player
o 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
Movement
o
Environmental interactions
o
Combat
o
Responses to game events
o
Querying and storing information
Later: animations
o Movement: limb and body animation
o 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 practical
o NPC should not make the game too difficult
o NPC AI needs to conserve system resources
o 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 complex
o
o
o
•
Very flexible
o
•
Emergent behavior based on desires, sensory input,
and proximity to objects of interest
Good response to unexpected events
Human-like behavior: reading books, drinking
water, opening doors, etc.
o
Developers can create an open world
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 concepts
o
o
o
o
o
o
o
o
Ownership
Dependency
Responsibility
Relevance
Priority
Consciousness
Expected state
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 actions
o
Atomic, inseparable action of using toilet and sink
o
Less reusability in other situations
Use dependency parameters: objects that
reference others by ID
Simple solution used in NOLF2
o
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 significance
o
Rabbits shouldn't be allowed
to use dramatic music when
being chased
Priority
•
•
•
"What is most important right now?"
Aggressive > Investigative > Relaxed
o
Investigating a dead body vs. being on guard
o
NPC defending himself vs. drinking coffee
Behavior priorities should persist until
behavior is completed
o
Highest priority goal controls behavior
State of Consciousness
•
•
"Am I awake?"
Unconscious NPCs have limited actions
o Can snore or wake up
•
o 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 consciousness
o
Ally caught in bear trap, ally is wounded, etc.
o
Footprints on floor
If object is not as expected the NPC
o
Investigates
o
Returns object to its default state
Disturbance threshold
o
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 room
o
•
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 NPCs
o
Easy but effective solution
o
Used in NOLF2
Split Up!
•
•
NPCs crowd corridors and rooms
Path reservation
o
o
o
•
o
Maximum Occupancy
o
o
o
•
Works best in combat scenarios
Reserve a path during planning
Path becomes more costly to other NPCs
Illusion of flanking and strategy
o
Works best in investigative scenarios
First NPC to reach a room flags it as occupied
Additional NPCs approach room but do not enter
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? Yes
2. Is obstruction an ally? Yes
3. Request ally ducks. If ally busy
4. 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 factors
o Sensory
o Memory
o Personality
o Emotions
o Physiological Stressors
Sensory
•
•
•
•
NPC's perception of its surroundings
o Most important: touch, sight, hearing
o Less important: smell, taste
Touch
o Detecting if NPC collided with something
Sight
o A vision cone based on distance
o Affected by lighting and obstacles
Hearing
o Listening for player movements, other game events
o 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 mechanics
o Thief
 Guards visually look for player

Guards react to corpses
 Guards listen for environment noises & footsteps
o
o
Skyrim

Armor weight, movement speed and proximity
affect movement noise

Attacking / casting spells / jumping increase noise
Assassin's Creed

Mostly visual
Stealth in Skyrim (1:04)
Memory, Personality, Emotions
•
•
•
•
How NPCs interact with the player
Memory
o
NPC learns from interactions
o
Short-term vs. long-term memory
Personality
o
Happy, sarcastic, antagonistic, etc.
o
"Big Five": Extraversion, agreeableness, conscientiousness,
neuroticism, openness
Emotions
o
The mood of NPCs
o
Happy, sad, angry, etc.
Memory, Personality, Emotions
•
Most useful for RPGs
o 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 body
o
Muscle fatigue
o
Pain
o
Health
o
Anxiety
o
Fear
o
Extreme temperatures
o
Chemicals
o
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 believable
o
•
•
NPC does not smile and greet you even after you killed their
entire village
Varies gameplay
o
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 II
o 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 oneon-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 III
o Good - Angel wings, Positive responses
o Bad - Bat wings, Negative responses
o Neutral - Eagle wings
Mass Effect 2
o Choose sides - Paragon / Renegade
Problems
o Not quite believable - NPCs appear to be psychic
o 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 believable
o
•
•
o
City guards would have a central command center
Reasonable to assume all guards share same info
Simpler solution
o
No need for event-based system
Skyrim
o
o
Windhelm guards do not arrest you for crimes
committed in Whiterun
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 event
o
NPC is within the area when an event occurs e.g.
when an NPC dies or is attacked
o
NPC comes in contact with another NPC that knows
of the event
Reputation changes aren't instantaneous
o
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 fullbody, 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 sense
o
Idle animations have priority of 0
o
Walks have priority of 5
o
Attacks have priority of 10
o
Reactions have priority of 20
o
Deaths have priority of 100
Each category corresponds to specific body
regions
o If the category is upper-body, animation data should
only be for bones from the waist up
Animating NPCs: Implementation
•
Animation controller class
o
Standard Template Library (STL) map which stores
animation instances, sorted by category
o
Animation instances reference a resource file
o
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 naturally
o Realistic movements
•
o Express emotions
Acts normally
o Does what they are supposed to do
•
o Behaves like a human being
Responds appropriately
o Knows if you are a friend or an enemy
o Makes human mistakes
Download