• Tidak ada hasil yang ditemukan

Index of /Kuliah2016-2017/KecerdasanBuatanUntukGame

N/A
N/A
Protected

Academic year: 2017

Membagikan "Index of /Kuliah2016-2017/KecerdasanBuatanUntukGame"

Copied!
28
0
0

Teks penuh

(1)

Artificial Intelligence in 

Game Design

(2)

Movement in Games

• Determine desired direction of movement of 

character in some space

– Can include  more complex components

• Speed

• Orientation • Acceleration

• Meant to meet some goal

– Pursuing  player – Fleeing  player

– Moving through obstacles – Wandering/patrolling

(3)

Types of Spaces

• Usually two dimensional

– Most games involve  “ground”

– Screen inherently  2D

• Can still use angles to appear  3D

• 2 ½ dimensional space

(4)

Basic Game Physics

• Representation:

– Position: X, Y

– Orientation: ω

Y X

(5)

Basic Game Physics

• Velocity and rotation

– velX

– velY

– velω

• Forces to change velocity

– Steering controlled  by player – steerX

– steerY

– steerω

“speed” = sqrt(velX2 + velY2)

(6)

Basic Game Physics

• Simple update algorithm:

Update(steerX, steerY, steerω, time) {

XX + velX * time

• Note that not perfect physics, but “close enough” for fast frame rate

(7)

Limitations in Game Physics

• Only accelerate  in current direction of steering  (facing)

– Direction of drive wheels in car – Direction of engines in rocket

• Single accel component  player controls

– Gas pedal, etc.

• steerX = accel * cos(ω) steerY = accel * sin(ω)

• Will need  to change ω

to achieve direction

– Target ω = atan(targetY ­ Y targetX ­ X)

targetX ­ X

(8)

Limitations in Game Physics

• Maximums on velocity and/or steering

– Max speed at which character can run  – Max gas flow/steering wheel turn in car

• Rotation/spin  set to maximum if exceed 

– If (vel ω > maxvel ω) vel ω = maxvel ω

• Directional  maximums usually  for total in both X, Y

speed = sqrt(velX2 + velY2) <= maxspeed

• Must normalize both to maximum

– velX = maxspeed * cos(ω) – velY = maxspeed * sin(ω)

velY speed

velX maxspeed

(9)

Limitations in Game Physics

• Drag slows velocities each  frame

– Atmospheric drag – Friction with ground – Underwater motion

• Can implement as drag  coefficient

– drag between 0 and 1

– speed = speed * (1 – drag)

– Normalize velX, velY based on  adjusted speed

velY

velX ω

(10)

Limitations in Game Physics

• Limits imposed  by animation

– Fixed number of motion animations rendered for “legged” characters

walk stride

(11)

Limitations in Game Physics

• May map actual velocities to those allowed  by animation

– In worst case define:

(12)

Steering Behaviors

• Define steering components  for NPC

– Determined in terms of goal of NPC – Usually very simple

– Can combine to create complex emergent behavior

• Examples:

– Seek – Flee – Arrive – Align – Pursue – Evade – Wander – Avoid

(13)

Steering Behaviors

Basic form of character motion:

• Use steering  behaviors to determine  desired steerX,  steerY, steerω

• May need to combine multiple behaviors

– Seek food – Flee predator

• Normalize  to maxX, maxY, maxω if necessary

• Apply update method to change  positions and velocities • Apply other constraints as necessary

– Drag

(14)

Seek Behavior

• Goal: 

Move to some specific location as fast as possible

– Goal location: (targetX, targetY)

– May be location of character or other objective

steerX = targetXX

steerY = targetY

– Probably larger than maximum acceleration, will  need to normalize

steerX

(15)

Flee Behavior

• Goal: 

Move away from some location as fast as possible

– Opposite of Seek

steerXX – targetX

steerYY – targetY

steerX

steerY

targetX ­ X

(16)

Arrive Behavior

• Problem with using seek to stop at location:

– Usually at maximum velocity when reach location – Will overshoot (possibly several times)

• Must decelerate when near location

accelerate

(17)

Arrive Behavior

• Decelerate  within some “slow radius”  of target

• Idea: 

Target velocity should decrease with distance to target

– distance = sqrt((targetX – X)2 + (targetY – Y)2)

targetSpeed = maxSpeed * distance / slowRadius

accelerate

(18)

Arrive Behavior

• Normalize  to get target velocity in each  dimension based on angle Ө to target

Ө = atan( ( targetY – Y) /  ( targetX ­ X))

 targetVelX = targetSpeed * cos(Ө) targetVelY = targetSpeed * sin(Ө)

• If target moving will need to adjust to  match speed

 targetVelX = targetVelX – locationVelX

 targetVelY = targetVelY – locationVelY

targetSpeed targetVelX

targetVelY

(19)

Arrive Behavior

• Problem: will never reach exact target point

– Movements not precise enough – Will just “hover” forever

• Solution: define small “close enough”  targetRadius – within targetRadius steerX = 0

steerY = 0

(20)

Arrive Behavior

Arrive( targetX, targetY, LocationVelX,  LocationVelY)  { distance = sqrt((targetX – X)2 + (targetY – Y)2)

if (distance <= targetRadius) { speedX = 0; speedY = 0; 

}

else if (distance <= slowRadius) {

targetSpeed = maxSpeed * distance / slowRadius;   

compute targetVelX, targetVelY components

adjust targetVelX, targetVelY to locationVelX,  locationVelY

MatchVelocity(targetVelX, targetVelY); }

else {

(21)

MatchVelocities Behavior

Set steering to achieve desired velocities as fast 

as possible

 steerX = targetVelX – velX

 steerY = targetVelY – velY

 May need several steps if more than maximum  acceleration!

(22)

Align Behavior

• Set orientation to some given targetω

• Like Arrive for orientation

– Define some slowAngle at which to slow rotation – Define some targetAngle at which to stop

– Spin as fast as possible outside slowAngle

targetω targetAngle

(23)

Pursue Behavior

Seek

does not work well for moving targets

Seek moves  to current  location of  target and  must readjust each frame

But target has moved away from target location

(24)

Pursue Behavior

• Compute distance to target

distance = sqrt((targetX – X)2 + (targetY – Y)2)

• Estimate time to target based on current speed

timeToTarget = distance / sqrt(velX2 + velY2)

• Estimate location  of target after that time based  on its  current speed

actualTargetX = targetX + velTargetX * timeToTarget actualTargetY = targetY + velTargetY * timeToTarget

• Move to that location as fast as possible

Seek (actualTargetX, actualTargetY) or

(25)

Pursue Behavior

• This is quick estimate of complex computation

– Time to intercept is just rough estimate

(26)

Evade Behavior

• Same idea as Pursue

– Anticipate where pursuer will  be

• Current location • Current speed

Flee from that location

(27)

Wander Behavior

• Goal: Have character “wander around”  at  “random”

• Problem: Moving in random direction  each frame just causes character to  ”hover” in same area

(28)

Wander Behavior

At each move:

• Place circle at some distance ahead of  character

– Good distance = maxSpeed

– Radius of circle = maximum turn in frame

Referensi

Dokumen terkait

➲ The rules that define the operation of the game world make up the core mechanics of the game, or the foundations of gameplay.. ➲ All games tell

Realitas tertambah dan dikenal dengan singkatan bahasa Inggrisnya AR ( augmented reality ), adalah teknologi yang menggabungkan benda maya dua teknologi yang menggabungkan

Remote Method 

Digunakan untuk membuat paket data yang disimpan dalam array of byte dan dikirim ke port tertentu...

Project management is the application of knowledge, skills, tools, and techniques to project activities in order to meet or exceed project activities in order to meet or exceed

pengangguran di atas 200 juta (sektor konstruksi, real estate, jasa keuangan, otomotif, dan sebagainya)..  Krisis ekonomi mengakibatkan situasi yang tidak menguntungkan bagi

Under seat D001 Computer Lab Kilcawley Center Holy Grail At podium Room 301 Meshel Hall Me Path to room 301 exit

The task of the algorithm is to estimate the location of this area on each subsequent frame or to determine that the object is not visible on the current frame.. For the