• 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

Bagi calon Penyedia barang/jasa diberi waktu masa sanggah selama 5 (lima) hari kerja dari tanggal 13 juli 2012 sampai dengan tanggal 19 Juli 2012 (sesuai jadwal LPSE);.

Operasi ekonomis tanpa kekangan, operasi ekonomis dengan kekangan pada sistem sintetis, operasi ekonomis dengan kekangan pada sistem real, dan optimasi hydro- thermis

menyatakan dengan sesungguhnya bahwa karya tulis ilmiah yang berjudul : “ Aplikasi Konsentrasi Bubur California dalam Biocoating terhadap Tingkat Serangan Busuk Buah

Bagi calon Penyedia barang/jasa diberi waktu masa sanggah selama 5 (lima) hari kerja dari tanggal 13 juli 2012 sampai dengan tanggal 19 Juli 2012 (sesuai jadwal LPSE);.

Penilaian dari pokok bahasan ini dilakukan pada akhir perkuliahan melalui pemberian problem yang berkaitan

ATAS NAMA TERDAKWA KAMALUDIN Alias JEFRI Alias ABDUL HAMID Alias GILANG RIDHO.. KETUA MAHKAMAH AGUNG REPUBLIK

Sub Kompetensi : Mahasiswa dapat memahami konsep komponen simetris dan penggunaannya pada analisis sistem tenaga listrik. Indikator Pencapaian Kompetensi : Mahasiswa

menyatakan dengan sesungguhnya bahwa karya tulis ilmiah yang berjudul : “ Aplikasi Konsentrasi Bubur California dalam Biocoating terhadap Tingkat Serangan Busuk Buah