41
Gameplay Presented by: Marcin Chady

Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Gameplay Presented by: Marcin Chady

Page 2: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Introduction

• What do we mean by gameplay?

– Interaction between the player and the game

• Distinguishing factor from non-interactive like as film and music

– Sometimes used interchangeably with “game mechanics”

• Gameplay components

– Game rules

– “AI”

– World representation

– Behaviour simulation

– Physics

– Camera

Page 3: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

What Do We Mean by AI?

• Making the AI challenging is not the hard part

– The game is omniscient and omnipotent, so it can always kick

your ass if it chooses to

– The trick is in making AI that is challenging yet realistically flawed

• Video games use a different definition of AI

– A lot of what games call “AI” isn't really intelligence at all, just

gameplay

– AI is the group of components that control the objects in the

game

– The AI is the heart of the game, and has the most influence on

how much fun the game is

Page 4: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

World Representation

• The AI needs to keep track of all of the objects in the

game

• An insultingly simple example:

– We can represent a tic-tac-toe board as a two dimensional array

of characters

• A slightly less insulting example:

– A Pong game consists of the coordinates of the ball, and the

positions of the paddles, as well as the locations of the walls

• More complicated games typically do not have a fixed

set of game entities

– Need a dynamic data structure to manage entities

Page 5: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

World Representation Purpose

• Some important first questions:

– How large is the world?

– How complex is the world?

– How far can you see?

– What operations will be performed?

• Visibility

• Audibility

• Path finding

• Proximity detection

• Collision detection

• Sending messages to groups of entities

• Dynamically loading sections of the world

Page 6: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

World Representation: Single List

• Simplest approach: one big list

– All search operations are pretty expensive

– But all operations are about the same

• i.e. no slower to search by name than by position

– Storage space and algorithm complexity are low

– Good for extremely simple games (< 100 entities)

• Can make it a little more useful with multiple lists

• In more complicated structures each world node may

have a list of entities in that node

Page 7: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Spatial World Representation

• Spatial data structures

– KD trees

– BSP

– Grid

– Graph

– Whatever

• Dictionary

– Spatial hashing

• Hybrid

– Big games use multiple techniques at the same time

– or different techniques for different kind of data

– each optimised for the particular queries on that data

Page 8: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Sphere of Influence

• Rather than simulating thousands of entities in a large world, many games maintain a small bubble of activity around the player – Or around the camera

– Could be somewhat off-centre

• Keeps the activity centered around the player

• The world outside the sphere is downgraded in fidelity, or shut off entirely – Typically multiple spheres for different types of entities

– Typically tied to level-of-detail (LOD) systems

• Entities can be recycled as they leave the sphere – Strive to recycle objects that aren't visible

– Or fade them in/out gently in the distance

Page 9: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Some Scenarios

• Prototype ambience spawn spheres:

• Prototype prop system:

– Props weighted by

• whether they’re on camera

• distance from camera

• physics state

• mission relevance

• size

– Only N highest-weighted props are spawned

– Culled props have their state saved to be restored later

• Some objects should be active well outside the normal

sphere

– Goals, powerups, mission-critical entities

Page 10: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Dynamic Entities

• The world is populated with a variety of dynamic entities:

– players (human & AI controlled)

– props

– power-ups

– rockets

– miscellaneous stuff that moves, animates, thinks, changes state,

or otherwise reacts to the game situation

• Usually modeled with:

– simplified spatial representation (for collision detection)

– state (idle, fighting, patrolling, dead, etc.)

– attributes (maximum speed, colour, health, etc.)

• Many ways to organize this data

– Covered in the “Game Architecture” lecture

Page 11: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Entity Behaviour

• We want our entities to do interesting things

• Two major strategies employed:

– Programming behaviour

– Simulating behaviour

• For example, consider the FPS cliché of the exploding

barrel

– How do we model this behaviour?

Page 12: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Programming Behaviour

• Explicitly add individual behaviours to entities

function barrel::collide(hit_by)

if hit_by.type == bullet

damage += 10

if damage >= 100

PlayAnimation(exploding)

PlaySound(exploding_barrel)

DestroySelf()

end

end

End

• Comments?

Page 13: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Comments

• Simple to implement

• Good for one-off, unique game events

– Cut-scene triggers

• Not flexible

• Misses out on emergent opportunities

– No splash damage or chain reaction explosions

– Doesn't explode when hit by rockets

• unless explicitly modified to do so

• Extending this model to complex interactions makes the

code unwieldy

– Numerous permutations have to be explicitly coded

Page 14: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Simulating Behaviour

• Define a few high-level rules that affects how objects

behave

• Combine these rules in interesting ways when objects

interact

– This is what computers are for, after all

• Properties of objects:

– GivesDamage(radius, amount)

– MaxDamageAbsorb(amount)

• Object will “break” if it absorbs enough damage

– BreakBehaviour(disappear | explode)

• Disappear destroys entity

• Explode destroys entity, and spawns a shock wave entity in its place

Page 15: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Entity Properties

• Entities in this example, and their properties:

– Bullet

• GivesDamage = 0.01, 10

• MaxDamageAbsorb = 0

• BreakBehaviour = disappear

– Barrel

• MaxDamageAbsorb = 100

• BreakBehaviour = explode

– Shockwave

• GivesDamage = 5.0, 50

Page 16: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Explosion Behaviour

function entity::collide(hit_by)

damage += hit_by.GivesDamage

if damage > MaxDamageAbsorb

switch BreakBehaviour

case disappear:

DestroySelf()

case explode:

Spawn(shockwave, position)

DestroySelf()

end

end

end

Page 17: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Comments

• Observed behaviour the same as the first example – when a lone barrel is shot

• A lot of nice behaviour can emerge – Splash damage and cascading barrel explosions

– Non bullet objects causing damage can be added easily

• Easy to add new properties and rules – A rocket is just a bullet with BreakBehaviour = explode

– Different damage classes

• e.g. electrical damage that only harms creatures, but doesn't affect inanimate objects

– CanBurn, EmitsHeat properties with rules for objects bursting into flames

• It doesn't take many of these rules to create a very rich environment – Be careful about undesired emergent behaviour

Page 18: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Triggers

• Very common way to initiate entity behaviour

• Common types: – Volume

– Time

• When the trigger condition is met (player occupies trigger volume, timer runs out, etc.): – Send event

– Run script

– Execute callback

• Triggers can be – One-shot

– Edge-triggered

– Continuous

• Games typically have a well developed trigger system available

Page 19: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions
Page 20: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

State Machines

• State machines are used to

control moderate to complex AI

behaviour

• Often implemented in an ad-hoc

manner with a big case

statement

– Fine for relatively simple state

machines

Idle

Walk

Run Fall

Get Up

Page 21: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Civilian States in Hulk: Ultimate Destruction

• Standing

• Walking

• Startled

• Running

• Cowering

• Held

• Animating

• Flying

• Falling

• HitWall

• HitGround

• Rolling

• LyingDown

• GettingUp

• TurningAround

• Sliding

Page 22: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

FSM Scripting at Radical

• Fight Tree: a combination of

– Hierarchical state machine

– Motion graph

– Decision tree

• A state node is one or more “action” objects that are

implemented in C++ or Lua

– E.g. play animation, play sound, start effect, run script, etc.

– Each action supports “Init(), Update(), Exit()” methods

– Also supported: jump to new state, spawn (layer) new state

• Spawned states operate like threads

• Makes the state machine hierarchical

– One action in any state can be a “master”, all others are slaves

• When master action ends, state exits

Page 23: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Motion Node Example

Play Hit Animation on the attacking character

Block Opportunity

Play Hit Sound

Time

Play Hit Animation on the character being hit

Exit to another node

Apply damage to the character being hit

Page 24: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions
Page 25: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

State Transitions in the Fight Tree

• Different ways transitions can be initiated: – All master actions in current node complete

• Next state is determined by evaluating the tree from the top

• Or by a sequence action present in the completed node

– Forced by the game

– Explicitly, through

• Execute action

• Spawn action

• Opportunity action, if conditions are met

• Conditions: – Small C++ or Lua objects that query game state and return true

or false

– Example: trigger entered, event fired, time elapsed, animation frame reached, etc.

– Can be chained together with AND, OR, NOT

Page 26: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Sequencing Actions

• The default behaviour is that all actions that make up a

state logically run simultaneously

• Often you want a queue or stack of actions, and run

them sequentially

– Build up complex operations by queuing actions

– When each action is finished the queue is advanced or the stack

is popped

• Decouples states in large state machines quite a bit

• States don't always need all the information to decide what state to

go to next

• States can be much more fine grained

Page 27: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Control

• The AI needs to map input events to actual game play

behaviour

• It’s useful to think of that happening in two steps:

– Events map to intentions

– Intentions map to behaviour within constraints

• Intentions are gameplay-level abstractions of user input

Page 28: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Mapping Events to Intentions

• The AI interprets a button press as an intention to

perform a certain action

• Often this is a simple mapping, but it can become

complex depending on the game

– For example, some games have camera-relative controls

– Fighting games require queueing of inputs

– Combos

Page 29: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Mapping Intentions to Behaviours

• There are constraints on allowable behaviours

– These constraints can be quite complex

• Physical constraints

• Logical constraints (rules)

• Rules can be implemented using conditions on state

machines

– In Prototype, there are a bunch of conditions that drive the main

character's state machine based upon player's input

– Likewise, enemy logic generates virtual button presses that are

processed in the same way.

Page 30: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Physics

• What do we mean by physics

– Rules by which objects move and react in the gameplay

environment

• This doesn't necessarily imply a sophisticated rigid body

dynamics system

– Pong modelled ideal inelastic collisions pretty well

• In fact, “real physics” is usually just a tool in the box

• Game physics implementors have considerably more

latitude to change the rules

– A lot of physics can be “faked” without going to a dynamics

engine

• How is physics used in a modern game?

Page 31: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Uses of Physics

• Collision detection – Detect interactions of entities in the environment, e.g. triggers

• Animation – Complex shapes and surfaces (chains, cloth, water)

– Realistic environment interactions (bounce, tumble, roll, slide)

– Reaction to forces (explosions, gravity, wind)

– Augment “canned” animation with procedural animation

– Hit reactions, “rag doll”

• Gameplay mechanics – Physics puzzles

– Driving, flying

– Compute damage

• Generate sounds

Page 32: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

AI Use of Physics

• Generally the AI keeps the physics system reigned in

– Objects only go into “full simulation mode” under specific

circumstances and often only for a limited period of time

• Example from Prototype:

– Traffic cars generally slide around the world on rails

– If an object appears in the car's “visibility cone”, it comes to a

gradual stop

– Traffic cars in “rail mode” can impart forces on other objects (peds)

– If the car collides with another car, the AI puts it into full simulation

• AI computes an impact force based upon collision information, and

tunables

• Car is placed under control of the rigid body system, and allowed to

bounce around until it comes to rest

• Then the car is put to sleep (removed from rigid body system)

• If it’s damaged it never returns to AI control

Page 33: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Interactions Between Objects

• As we’ve seen in the example, some objects in the world are under physics control, and other are under AI control

• What happens when they collide? – To the physics system, AI controlled objects don't follow the rules

• Velocities, positions are under AI control

• Properties like mass, and friction, and restitution may not be defined for AI controlled entities

• There needs to be a mechanism to compute plausible forces to pass to the physics system to apply to the simulated object

• Likewise, the AI controlled object will have some sort of collision response programmed into it – Play animation, move object, apply damage, trigger sounds,

change entity state, etc.

Page 34: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Physics Hand-off

• When the AI places an object into full simulation, it sets up the initial conditions for the object's rigid body – Position, velocity, angular velocity

• In the simplest form, the AI-managed position and velocities are copied into the rigid body

• There may be considerable massaging of the conditions to make the response more interesting, or realistic-appearing

• Example from Hulk 2 and Prototype: – When Hulk elbows a car, angular velocity is carefully chosen to

make it launch up into the air, tumble end-over-end (with variation), and land close behind him

– Thrown objects are kept out of general physics simulation until they hit something

Page 35: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Tuning

• Physical simulations can produce a lot of emergent

behaviour

• This can be good

– Adds variety to gameplay and presentation

– Players can discover or create situations that weren't envisioned

by the designer

• This can be bad

– Players can discover or create situations that weren't envisioned

by the designer

• Exploits, bugs, other bizarre behaviour

• Emergent systems are hard to tune!

Page 36: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Realism, Accuracy and Fun

• Realism is a powerful tool, but it is not the end goal for

video games.

• There are differences between what people believe is

realistic, and real-world behaviour.

– “Real” realism is usually pretty boring

• Games provide a small amount of feedback and control

compared to their real-life counterparts

• Physical simulation and hacks can live comfortably side-

by-side.

Page 37: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Cameras

• AI camera models are usually motivated by:

– Gameplay goals

• Need to see player

• Need to see important AI entities

• Intuitive controls

– Cinematic goals

• Look cool

• Camera design is primarily an AI / gameplay issue

– Not rendering!

Page 38: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Camera Models

• Simple camera models: – Fixed: the camera never moves

– Tracking: the camera doesn’t move, but points at an interesting object

– Follow: the camera follows at a distance behind the target

• More sophisticated camera systems handle things like: – obstacle avoidance

– framing

– line of sight

• Instant replay camera: – Scripted camera animations

– User controlled cameras

• Artists controlled cameras – Shot setup and animation done in 3D modeling/animation tool

Page 39: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Camera Models for Driving Games

• First-person – Glue camera to bumper

– Tune field-of-view to create enhanced sense of speed

• More effective than tuning actual vehicle speed

• Third-person – Camera tracks behind the car at some distance

– Perfect tracking doesn't look good

• Car is locked to the centre of the screen

– Add anticipation and lag to the camera movement

• When braking, move camera closer

• When accelerating, move further

• Look into direction of turns

• Lower/raise camera based on velocity of car

– Don't spin camera right away if car is spinning

Page 40: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions

Summary

• Gameplay is huge

– Touches on every part of the system

– Needs every trick from the bag

• Many areas weren’t covered

– Path finding

• Will talk about it in the driving lecture

– Enemy AI

• Too wide and game-specific to cover here

– AI animation control

• Covered superficially when talking about Radical’s Fight Tree

• Will talk about it a bit later

Page 41: Presented by: Marcin Chadypages.cpsc.ucalgary.ca/~bdstephe/585_W12/d201_gameplay.pdf · 2012-01-08 · •Logical constraints (rules) • Rules can be implemented using conditions