42
GAMEPLAY GAMEPLAY

Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

GAMEPLAYGAMEPLAY

Page 2: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

IntroductionIntroduction

• What do we mean by gameplay?What do we mean by gameplay?• ““AI”AI”• World representationWorld representation• Behaviour simulationBehaviour simulation• PhysicsPhysics• CameraCamera

Page 3: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

What do we mean by AI?What do we mean by AI?

• Artificial vs. Synthetic IntelligenceArtificial vs. Synthetic Intelligence– Artificial intelligence tries to generate “real” reasoning or Artificial intelligence tries to generate “real” reasoning or

information processing abilityinformation processing ability

– Synthetic intelligence tries to produce the appearance of Synthetic intelligence tries to produce the appearance of intellectintellect

– Games are mostly synthetic intelligenceGames are mostly synthetic intelligence

• Some solutions come from “real” AI, but not a lotSome solutions come from “real” AI, but not a lot

Page 4: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

What do we mean by AI?What do we mean by AI?

• Making the AI “smart” is not the hard partMaking the AI “smart” is not the hard part– The game is omniscient and omnipotent, therefore the game The game is omniscient and omnipotent, therefore the game

can always kick your ass if it wants tocan always kick your ass if it wants to– The trick is in making AI that is challenging, but realistically The trick is in making AI that is challenging, but realistically

flawedflawed• Video games use a different definition of AIVideo games use a different definition of AI

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

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

– The AI is the heart of the game, and has the most influence The AI is the heart of the game, and has the most influence on how much fun the game is.on how much fun the game is.

Page 5: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

World RepresentationWorld Representation

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

• An insultingly simple example:An insultingly simple example:– We can represent a tic-tac-toe board as a two dimensional We can represent a tic-tac-toe board as a two dimensional

array of charactersarray of characters

• A slightly less insulting example:A slightly less insulting example:– A Pong game consists of the coordinates of the ball, and the A Pong game consists of the coordinates of the ball, and the

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

• More complicated games typically do not have a fixed More complicated games typically do not have a fixed set of game entitiesset of game entities

• Need a dynamic data structure to manage entitiesNeed a dynamic data structure to manage entities

Page 6: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

World RepresentationWorld Representation

• Some important first questions:Some important first questions:– How large is the world?How large is the world?– How complex is the world?How complex is the world?– How far can you see?How far can you see?– What operations will be performed?What operations will be performed?

• Visibility Visibility • AudibilityAudibility• Path findingPath finding• Proximity detectionProximity detection• Collision detectionCollision detection• Sending messages to groups of entitiesSending messages to groups of entities• Dynamically loading sections of worldDynamically loading sections of world

Page 7: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

World Representation (cont’d)World Representation (cont’d)

• Simplest : One big listSimplest : One big list– All search operations are pretty expensiveAll search operations are pretty expensive

• But all operations are about the sameBut all operations are about the same

– i.e. No slower to search by name than by positioni.e. No slower to search by name than by position

– Storage space and algorithm complexity are lowStorage space and algorithm complexity are low

– Good for extremely simple games (< 100 entities)Good for extremely simple games (< 100 entities)

• Can make it a little more useful with multiple listsCan make it a little more useful with multiple lists• Also, usually in more complicated structures, each Also, usually in more complicated structures, each

node will have a list of the entities in that nodenode will have a list of the entities in that node

Page 8: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

World Representation (cont’d)World Representation (cont’d)

• Spatial data structuresSpatial data structures– KD / BSP / grid / whateverKD / BSP / grid / whatever

• DictionaryDictionary• HybridHybrid

– Big games use multiple techniques at the same time, or Big games use multiple techniques at the same time, or different techniques for different kind of data, each optimised different techniques for different kind of data, each optimised for the particular queries on that datafor the particular queries on that data

Page 9: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Sphere of InfluenceSphere of Influence

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

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

• Keeps the activity centered around the playerKeeps the activity centered around the player• Entities can be recycled as they leave the sphereEntities can be recycled as they leave the sphere

– Try to recycle objects that aren't visibleTry to recycle objects that aren't visible

– H&R: The sphere isn't centered on the player, the player stands H&R: The sphere isn't centered on the player, the player stands near the back of the spherenear the back of the sphere

Page 10: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

VariationsVariations

• Hulk 2 : Instantiate Hulk 2 : Instantiate NN closest props closest props• Prototype: Instantiate Prototype: Instantiate NN most prominent props on screen most prominent props on screen• H&R: Uses path distance rather than crow-flies distanceH&R: Uses path distance rather than crow-flies distance• H&R: Prefer objects that the user hasn't interacted with H&R: Prefer objects that the user hasn't interacted with

when recyclingwhen recycling • If you have to recycle something in view, fade it, don't pop it If you have to recycle something in view, fade it, don't pop it

out of existenceout of existence• Some gameplay objects should be active well outside the Some gameplay objects should be active well outside the

normal spherenormal sphere– Goals, powerups, mission-crucial entitiesGoals, powerups, mission-crucial entities

Page 11: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

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

– players (human & AI controlled)players (human & AI controlled)– propsprops– power-upspower-ups– rocketsrockets– miscellaneous stuff that moves, animates, thinks, changes state, miscellaneous stuff that moves, animates, thinks, changes state,

or otherwise reacts to the game-situationor otherwise reacts to the game-situation• Usually modeled with:Usually modeled with:

– simplified spatial representation (for collision detection)simplified spatial representation (for collision detection)– state (idle,fighting, patrolling, dead, etc.)state (idle,fighting, patrolling, dead, etc.)– attributes (maximum speed, colour, health, etc.)attributes (maximum speed, colour, health, etc.)

• Many ways to organize this dataMany ways to organize this data– Covered in the “Game Architecture” presentationCovered in the “Game Architecture” presentation

Page 12: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Entity BehaviourEntity Behaviour

• We want our entities to do interesting thingsWe want our entities to do interesting things• Two major strategies employed:Two major strategies employed:

– Programming behaviourProgramming behaviour– Simulating behaviourSimulating behaviour

• For example, consider the FPS cliché of the exploding For example, consider the FPS cliché of the exploding barrelbarrel– How do we model this behaviour?How do we model this behaviour?

Page 13: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Programming BehaviourProgramming Behaviour

• Explicitly add individual behaviours to entitiesExplicitly add individual behaviours to entities

function barrel::collide( hit_by )function barrel::collide( hit_by )

if hit_by.type == bulletif hit_by.type == bullet

damage += 10damage += 10

if damage >= 100if damage >= 100

PlayAnimation( exploding )PlayAnimation( exploding )

PlaySound( exploding_barrel )PlaySound( exploding_barrel )

DestroySelf()DestroySelf()

endend

endend

endend

Page 14: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

CommentsComments

• Simple to implementSimple to implement• Good for one-off, unique game eventsGood for one-off, unique game events

– Cut-scene triggersCut-scene triggers• Not flexibleNot flexible• Misses out on emergent opportunitiesMisses out on emergent opportunities

– No chain reaction explosionsNo chain reaction explosions– Doesn't explode when hit by rockets unless explicitly modified to do Doesn't explode when hit by rockets unless explicitly modified to do

soso– No splash damageNo splash damage

• Extending this model to complex interactions makes the Extending this model to complex interactions makes the code unwieldy as numerous permutations have to be code unwieldy as numerous permutations have to be explicitly codedexplicitly coded

Page 15: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Simulating BehaviourSimulating Behaviour

• Define a few high-level rules that affects how objects Define a few high-level rules that affects how objects behavebehave– Combine these rules in interesting ways when objects interact Combine these rules in interesting ways when objects interact

• Properties of objects:Properties of objects:– GivesDamage( radius, amount )GivesDamage( radius, amount )– MaxDamageAbsorb( amount )MaxDamageAbsorb( amount )

• Object will “break” if it absorbs enough damageObject will “break” if it absorbs enough damage– BreakBehaviour( disappear | explode )BreakBehaviour( disappear | explode )

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

placeplace

Page 16: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Entity PropertiesEntity Properties

• Entities in this example, and their properties:Entities in this example, and their properties:– BulletBullet

• GivesDamage = 0.01, 10GivesDamage = 0.01, 10• MaxDamageAbsorb = 0MaxDamageAbsorb = 0• BreakBehaviour = disappearBreakBehaviour = disappear

– BarrelBarrel• MaxDamageAbsorb = 100MaxDamageAbsorb = 100• BreakBehaviour = explodeBreakBehaviour = explode

– ShockwaveShockwave• GivesDamage = 5.0, 50GivesDamage = 5.0, 50

Page 17: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Explosion BehaviourExplosion Behaviour

function entity::collide( hit_by )function entity::collide( hit_by )

damage += hit_by.GivesDamagedamage += hit_by.GivesDamage

if damage > MaxDamageAbsorbif damage > MaxDamageAbsorb

switch BreakBehaviourswitch BreakBehaviour

case disappear:case disappear:

DestroySelf()DestroySelf()

case explode:case explode:

Spawn( shockwave, position )Spawn( shockwave, position )

DestroySelf()DestroySelf()

endend

endend

endend

Page 18: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

CommentsComments• Observed behaviour the same as the first example when a lone Observed behaviour the same as the first example when a lone

barrel is shotbarrel is shot• A lot of nice behaviour can emergeA lot of nice behaviour can emerge

– Cascading barrel explosionsCascading barrel explosions– Non bullet objects causing damage can be added easilyNon bullet objects causing damage can be added easily– Splash damageSplash damage

• Easy to add new properties and rulesEasy to add new properties and rules– A rocket is just a bullet with BreakBehaviour = explodeA rocket is just a bullet with BreakBehaviour = explode– Different damage classes (e.g. Electrical damage that only harms Different damage classes (e.g. Electrical damage that only harms

creatures, but doesn't affect inanimate objects)creatures, but doesn't affect inanimate objects)– CanBurn, EmitsHeat properties with rules for objects bursting into flameCanBurn, EmitsHeat properties with rules for objects bursting into flame

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

Page 19: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

BreakBreak

Page 20: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

TriggersTriggers

• Very common way to initiate entity behaviourVery common way to initiate entity behaviour• Common types:Common types:

– VolumeVolume– SurfaceSurface– TimeTime

• When the trigger condition is met (player occupies trigger When the trigger condition is met (player occupies trigger volume, timer runs out, etc.):volume, timer runs out, etc.):– Send eventSend event– Run scriptRun script– Execute callbackExecute callback

• Triggers can be Triggers can be one-shotone-shot, , edge-triggered, continuousedge-triggered, continuous• Games typically have a well developed trigger system Games typically have a well developed trigger system

availableavailable

Page 21: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

State MachinesState Machines

• State machines are used to control moderate to State machines are used to control moderate to complex AI behaviour.complex AI behaviour.

• They are often implemented in an ad-hoc manner They are often implemented in an ad-hoc manner with a big case statement.with a big case statement.– Fine for relatively simple state machinesFine for relatively simple state machines

• We use a graphical state machine editor for We use a graphical state machine editor for modeling complex entity behaviourmodeling complex entity behaviour

Page 22: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Example State MachineExample State Machine

• StandingStanding• WalkingWalking• StartledStartled• RunningRunning• CoweringCowering• HeldHeld• AnimatingAnimating• FlyingFlying

• FallingFalling• HitWallHitWall• HitGroundHitGround• RollingRolling• LyingDownLyingDown• GettingUpGettingUp• TurningAroundTurningAround• SlidingSliding

• Hulk: Ultimate Destruction “Civilian” animation / Hulk: Ultimate Destruction “Civilian” animation / behaviour states:behaviour states:

Page 23: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

State Machine Example (Hulk 2)State Machine Example (Hulk 2)

• A state node is one or more “action” objects that are A state node is one or more “action” objects that are implemented in C++ or Lua.implemented in C++ or Lua.– Each object supports “Init(), Update(), Exit()” methodsEach object supports “Init(), Update(), Exit()” methods– Example actions: play sound, play animation, start effect, run script, Example actions: play sound, play animation, start effect, run script,

change game statechange game state– Also: Jump to new state, spawn (layer) new stateAlso: Jump to new state, spawn (layer) new state

• Spawned states operate like threadsSpawned states operate like threads• Makes the state machine hierarchicalMakes the state machine hierarchical

– One action in any state can be a “master”, all others are slavesOne action in any state can be a “master”, all others are slaves• When master action ends, state exitsWhen master action ends, state exits

Page 24: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

State Machines: TransitionsState Machines: Transitions

• Different ways transitions can be initiated:Different ways transitions can be initiated:– Explicitly (executing a node)Explicitly (executing a node)– All actions in current node completeAll actions in current node complete– Conditions in current node evaluate to falseConditions in current node evaluate to false– Transition condition in explicit destination node evaluates Transition condition in explicit destination node evaluates

to trueto true• Conditions:Conditions:

– Small C++ or Lua objects that query game state and Small C++ or Lua objects that query game state and return true or falsereturn true or false

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

– Can be chained together with Can be chained together with andand, , oror, , notnot

Page 25: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Sequencing actionsSequencing actions

• The default behaviour is that all actions that make up The default behaviour is that all actions that make up a state logically run simultaneouslya state logically run simultaneously

• Often you want a queue or stack of actions, and run Often you want a queue or stack of actions, and run them sequentiallythem sequentially– Build up complex operations by queuing actionsBuild up complex operations by queuing actions

• When each action is finished the queue is advanced or When each action is finished the queue is advanced or the stack is poppedthe stack is popped

– Decouples states in large state machines quite a bitDecouples states in large state machines quite a bit• States don't always need all the information to decide States don't always need all the information to decide

what state to go to next.what state to go to next.– States can be much more fine grainedStates can be much more fine grained

Page 26: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

ControlControl

• The AI needs to map input events to actual game play The AI needs to map input events to actual game play behaviour. It’s useful to think of that happening in two behaviour. It’s useful to think of that happening in two steps:steps:– events map to intentionsevents map to intentions

– intentions map to behaviour within constraintsintentions map to behaviour within constraints

• Intentions are gameplay-level abstractions of user Intentions are gameplay-level abstractions of user inputinput

Page 27: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Mapping Events to IntentionsMapping Events to Intentions

• The AI interprets a button press as an intention to The AI interprets a button press as an intention to perform a certain actionperform a certain action

• Often this is a simple mapping, but it can become Often this is a simple mapping, but it can become complex depending on the gamecomplex depending on the game– For example, some games have camera-relative controlsFor example, some games have camera-relative controls

– Fighting games require queueing of inputsFighting games require queueing of inputs

– CombosCombos

Page 28: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Mapping Intentions to BehavioursMapping Intentions to Behaviours

• There are constraints on allowable behavioursThere are constraints on allowable behaviours– these constraints can be quite complexthese constraints can be quite complex

– physical constraintsphysical constraints

– logical constraints (rules)logical constraints (rules)

• Rules can be implemented using conditions on state Rules can be implemented using conditions on state machines.machines.– In Hulk 2, there are a bunch of conditions that drive In Hulk 2, there are a bunch of conditions that drive

the main character's state machine based upon the main character's state machine based upon player's input.player's input.

– Likewise, enemy logic generates virtual button Likewise, enemy logic generates virtual button presses that are processed in the same way.presses that are processed in the same way.

Page 29: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

PhysicsPhysics

• What do we mean by physicsWhat do we mean by physics– Rules by which objects move and react in the gameplay Rules by which objects move and react in the gameplay

environmentenvironment• This doesn't necessarily imply a sophisticated rigid body This doesn't necessarily imply a sophisticated rigid body

dynamics systemdynamics system– Pong modeled ideal inelastic collisions pretty wellPong modeled ideal inelastic collisions pretty well

• In fact, “real physics” is usually just a tool in the boxIn fact, “real physics” is usually just a tool in the box• Game physics implementors have considerably more Game physics implementors have considerably more

latitude to change the ruleslatitude to change the rules• A lot of physics can be “faked” without going to a dynamics A lot of physics can be “faked” without going to a dynamics

engineengine• How is physics used in a modern game?How is physics used in a modern game?

Page 30: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Uses of PhysicsUses of Physics• Collision detectionCollision detection

– Detect interactions of entities in the environment, e.g. triggersDetect interactions of entities in the environment, e.g. triggers• AnimationAnimation

– Complex shapes and surfaces (chains, cloth, water)Complex shapes and surfaces (chains, cloth, water)– Realistic collision interactions that respond to the environment Realistic collision interactions that respond to the environment

(bounce, tumble, roll, slide)(bounce, tumble, roll, slide)– Reaction to forces (explosions, gravity, wind)Reaction to forces (explosions, gravity, wind)– Augment “canned” animation with procedural animationAugment “canned” animation with procedural animation

• Hit reactions, “rag doll”Hit reactions, “rag doll”• Gameplay mechanicsGameplay mechanics

– Physics puzzlesPhysics puzzles– Driving, flyingDriving, flying– Compute damageCompute damage

• Generate soundsGenerate sounds

Page 31: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

AI use of PhysicsAI use of Physics• Generally the AI keeps the physics system reigned in most Generally the AI keeps the physics system reigned in most

of the timeof the time• Objects only go into “full simulation mode” under specific Objects only go into “full simulation mode” under specific

circumstances, and often only for a limited period of timecircumstances, and often only for a limited period of time• Example (H&R):Example (H&R):

– Traffic cars generally slide around the world on railsTraffic cars generally slide around the world on rails– If an object appears in the car's “visibility cone”, it comes to a If an object appears in the car's “visibility cone”, it comes to a

gradual stopgradual stop– Traffic cars in “rail mode” can impart forces on other objectsTraffic cars in “rail mode” can impart forces on other objects– If the car collides with another car, the AI puts it into full simulationIf the car collides with another car, the AI puts it into full simulation

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

• Car is placed under control of the rigid body system, and allowed Car is placed under control of the rigid body system, and allowed to bounce around until it stops movingto bounce around until it stops moving

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

Page 32: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Interactions Between ObjectsInteractions Between Objects

• In the example given, some objects in the world are under In the example given, some objects in the world are under physics control, and other are under AI controlphysics control, and other are under AI control

• How are collisions handled?How are collisions handled?– Issue: To the physics system, AI controlled objects don't follow the Issue: To the physics system, AI controlled objects don't follow the

rulesrules• Velocities, positions are under AI controlVelocities, positions are under AI control• Properties like mass, and friction, and restitution may not be Properties like mass, and friction, and restitution may not be

defined for AI controlled entitiesdefined for AI controlled entities– There needs to be a mechanism to compute plausible forces to pass There needs to be a mechanism to compute plausible forces to pass

to the physics system to apply to the simulated objectto the physics system to apply to the simulated object– Likewise, the AI controlled object will have some sort of collision Likewise, the AI controlled object will have some sort of collision

response programmed into itresponse programmed into it• Move object, apply damage, trigger sounds, change entity state, Move object, apply damage, trigger sounds, change entity state,

etc.etc.

Page 33: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Physics Hand-offPhysics Hand-off• When the AI places an object into full simulation, it sets up When the AI places an object into full simulation, it sets up

the initial conditions for the object's rigid bodythe initial conditions for the object's rigid body– Position, velocity, angular velocityPosition, velocity, angular velocity

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

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

• Example (Hulk 2)Example (Hulk 2)– When Hulk elbows a car, angular velocity is carefully chosen to When Hulk elbows a car, angular velocity is carefully chosen to

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

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

Page 34: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

TuningTuning

• Physical simulations can produce a lot of emergent Physical simulations can produce a lot of emergent behaviourbehaviour

• This can be goodThis can be good– adds variety to gameplay and presentationadds variety to gameplay and presentation– players can discover or create situations that weren't envisioned by players can discover or create situations that weren't envisioned by

the designerthe designer• This can be badThis can be bad

– players can discover or create situations that weren't envisioned by players can discover or create situations that weren't envisioned by the designerthe designer

• exploits, bugs, other bizarre behaviourexploits, bugs, other bizarre behaviour• Emergent systems are hard to tune!Emergent systems are hard to tune!

Page 35: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Realism, Accuracy and FunRealism, Accuracy and Fun

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

• There are differences between what people believe is There are differences between what people believe is realistic, and real-world behaviour.realistic, and real-world behaviour.– ““Real” realism is usually pretty boringReal” realism is usually pretty boring

– Games provide a small amount of feedback and control compared to Games provide a small amount of feedback and control compared to their real-life counterpartstheir real-life counterparts

• Physical simulation and hacks can live comfortably side-by-Physical simulation and hacks can live comfortably side-by-side.side.

Page 36: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

CamerasCameras

• AI camera models are usually motivated by:AI camera models are usually motivated by:– gameplay goalsgameplay goals

• need to see playerneed to see player

• need to see important AI entitiesneed to see important AI entities

• intuitive controlsintuitive controls

– cinematic goalscinematic goals

• look coollook cool

• Camera design is primarily an AI / gameplay issueCamera design is primarily an AI / gameplay issue– Not rendering!Not rendering!

Page 37: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Camera ModelsCamera Models

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

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

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

Page 38: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Advanced Camera ModelsAdvanced Camera Models

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

– framingframing

– line of sightline of sight

Page 39: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Cinematic ModelsCinematic Models

• Instant replay camera:Instant replay camera:– scripted camera animationsscripted camera animations

– user controlled camerasuser controlled cameras

• Artists controlled camerasArtists controlled cameras– shot setup and animation done in 3D modeling/animation toolshot setup and animation done in 3D modeling/animation tool

Page 40: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

Camera Models for Driving GamesCamera Models for Driving Games

• First-personFirst-person– glue camera to bumperglue camera to bumper– tune field-of-view to create enhanced sense of speedtune field-of-view to create enhanced sense of speed

• more effective than tuning actual vehicle speedmore effective than tuning actual vehicle speed• Third-personThird-person

– Camera tracks behind the car at some distanceCamera tracks behind the car at some distance– Perfect tracking doesn't look good (car is locked to the centre of the Perfect tracking doesn't look good (car is locked to the centre of the

screen)screen)– Add anticipation and lag to the camera movementAdd anticipation and lag to the camera movement

• When braking, move camera closer, when accelerating, move When braking, move camera closer, when accelerating, move furtherfurther

• Look into direction of turnsLook into direction of turns• Lower/raise camera based on velocity of carLower/raise camera based on velocity of car

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

Page 41: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call

ConclusionConclusion

• Two big areas we didn't cover:Two big areas we didn't cover:– AI animation controlAI animation control

• Not hugely important for your gameNot hugely important for your game• Will talk about it a bit laterWill talk about it a bit later

– Path findingPath finding• Will talk about it during the driving lectureWill talk about it during the driving lecture

Page 42: Gameplay - University of Calgary in Albertapages.cpsc.ucalgary.ca/~bdstephe/585_W09/d201_gameplay.pdf · • Video games use a different definition of AI – A lot of what games call