Post on 19-Jan-2016
transcript
15-466
Computer Game Programming
Movement: Basic Movement
Maxim Likhachev
Robotics Institute
Carnegie Mellon University
Maxim Likhachev Carnegie Mellon University 2
Overall Movement Hierarchy
Maxim Likhachev Carnegie Mellon University 3
Overall Movement Hierarchy
based on the state of the
game decides action and
computes a path
computes the desired
direction of the motion at
every frame
computes the actual
direction of the motion at
every frame
simulates the motion and
updates the position/velocity
of the character
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev
computes the actual
direction of the motion at
every frame
Carnegie Mellon University 4
Overall Movement Hierarchy
based on the state of the
game decides action and
computes a path
computes the desired
direction of the motion at
every frame
simulates the motion and
updates the position/velocity
of the character
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 5
Overall Movement Hierarchy
decide on action
compute path
compute motion
velocity
simulate motion
and update
position/velocity
state of the game
Maxim Likhachev Carnegie Mellon University 6
Overall Movement Hierarchy
decide on action
compute path
compute motion
velocity
simulate motion
and update
position/velocity
state of the game
compute motion
direction
compute motion
velocity
=
Maxim Likhachev Carnegie Mellon University 7
Definition of the System
compute motion
direction
compute motion
velocity
• Coordinate system for position P=[x,z] or P=[x,y,z]
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 8
Definition of the System
compute motion
direction
compute motion
velocity
• Coordinate system for orientation Ψ (in rads)
orientation is where it
looks (not necessarily
where it goes)
character is reduced to
a point
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 9
Definition of the System
compute motion
direction
compute motion
velocity
State of system:position P = [x,z]
• Kinematic movement
Maxim Likhachev Carnegie Mellon University 10
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
• Kinematic movement
Maxim Likhachev Carnegie Mellon University 11
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
• Kinematic movement
What Ψ should be set to?
Maxim Likhachev Carnegie Mellon University 12
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
• Kinematic movement
Any problems with this
approach?
Maxim Likhachev Carnegie Mellon University 13
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
• Kinematic movement
Any solutions?
Maxim Likhachev Carnegie Mellon University 14
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
• Kinematic movement
instantaneous changes to
orientation & velocity can
be smoothed out here by
interpolation
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 15
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
• Kinematic movement
Output of the overall system: V, Ψ
Maxim Likhachev Carnegie Mellon University 16
Definition of the System
compute motion
direction
compute motion
velocity
State of system:position P = [x,z],
velocity V = [Vx,Vy] =[magnitude v, direction θ],
orientation Ψ
angular speed dΨ
• Dynamic movement
Maxim Likhachev Carnegie Mellon University 17
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:acceleration A = [Ax,Az],
angular acceleration ddΨ
• Dynamic movement
Maxim Likhachev Carnegie Mellon University 18
Definition of the System
compute motion
direction
compute motion
velocity
Output of system:acceleration A = [Ax,Az],
angular acceleration ddΨ
• Dynamic movement
Output of the overall system: V, Ψ
Also limit V, dΨ to
their max values
Maxim Likhachev Carnegie Mellon University 19
Position Update According to Motion Equation
• Continuous formulation for constant acceleration:
simulate motion
and update
position/velocity
atvtv
vtvat
dtdt
dvadt
dt
dva
t t
0
0
0 0
)(
)(
2
00
0
2
0
0
0
0
0 0
2
1)(
)(2
1
)()(
attvPtP
PtPattv
PtPdtatv
dtdt
dPvdt
dt
dPv
t
t t
compute motion
velocity
Maxim Likhachev Carnegie Mellon University 20
Position Update According to Motion Equation
• Continuous formulation for constant acceleration:
simulate motion
and update
position/velocity
2
00
0
2
0
0
0
0
0 0
2
1)(
)(2
1
)()(
attvPtP
PtPattv
PtPdtatv
dtdt
dPvdt
dt
dPv
t
t tsame derivation for
orientation Ψ and angular
speed dΨ
compute motion
velocityatvtv
vtvat
dtdt
dvadt
dt
dva
t t
0
0
0 0
)(
)(
Maxim Likhachev Carnegie Mellon University 21
Position Update According to Motion Equation
• Discrete formulation:
V[t+1] = V[t] + A[t]∆t
P[t+1] = P[t] + V[t]∆t + 0.5A[t]∆t2
dΨ[t+1] = dΨ[t] + ddΨ[t]∆t
Ψ[t+1] = Ψ[t] + dΨ[t]∆t + 0.5ddΨ[t]∆t2
simulate motion
and update
position/velocity
compute motion
velocity
Units for ∆t?
Maxim Likhachev Carnegie Mellon University 22
Position Update According to Motion Equation
• Discrete formulation simplified:
V[t+1] = V[t] + A[t]∆t
P[t+1] = P[t] + V[t]∆t
dΨ[t+1] = dΨ[t] + ddΨ[t]∆t
Ψ[t+1] = Ψ[t] + dΨ[t]∆t
simulate motion
and update
position/velocity
compute motion
velocity
Why can we do it?
Maxim Likhachev Carnegie Mellon University 23
Kinematic Seek Behavior
• Move towards a target point T
V=[v, θ]= [max. speed,λ]
Ψ=λ
P
T
compute motion
direction
λ
How do we do flee?
Maxim Likhachev Carnegie Mellon University 24
Kinematic Flee Behavior
• Move away from a target point T
V=[v, θ]= [max. speed,λ+π]
Ψ=λ+π
P
T
compute motion
direction
λ
Maxim Likhachev Carnegie Mellon University 25
Kinematic Seek Behavior
• Move towards a target point T
V=[v, θ]= [max. speed,λ]
Ψ=λ
P
T
compute motion
direction
λ
Problems approaching a
moving target?
Solutions?
Maxim Likhachev Carnegie Mellon University 26
Kinematic Arrival Behavior
• Approach a target point T
if d < arrival radius
V=[v, θ]= [0,λ]
Ψ=λ
else
V=[v, θ]= [K*d,λ] for some constant K
Ψ=λ
P
T
compute motion
direction
λ
d
Familiar to control
folks?
Maxim Likhachev Carnegie Mellon University 27
Kinematic Wander Behavior
• Random wandering
dΨ = random with bias towards 0
Ψ= Ψ+dΨ
V=[v, θ]= [max. speed,Ψ]
compute motion
direction
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 28
Dynamic Seek Behavior
• Move towards a target point T
A=max. accel *normalize([dx,dz])
ddΨ=K(Ψ-λ) limited by max. angular acceleration
P
T
compute motion
direction
λ
ddz
dx
Take care for angle
wrapping
Maxim Likhachev Carnegie Mellon University 29
Dynamic Seek Behavior
• Move towards a target point T
A=max. accel *normalize([dx,dz])
ddΨ=K(Ψ-λ) limited by max. angular acceleration
P
T
compute motion
direction
λ
How do we do flee?
ddz
dx
Take care for angle
wrapping
Maxim Likhachev Carnegie Mellon University 30
Dynamic Flee Behavior
• Move away from a target point T
A=-max. accel *normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
P
T
λ
ddz
dx
Maxim Likhachev Carnegie Mellon University 31
Dynamic Flee Behavior
• Move away from a target point T
A=-max. accel *normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 32
Dynamic Flee Behavior
• Move away from a target point T
A=-max. accel *normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
http://www.red3d.com/cwr/steer/SeekFlee.html
Maxim Likhachev Carnegie Mellon University 33
Dynamic Arrive Behavior
• Approach a target point T
if d < arrival radius then vdes=0
else vdes=K*d for some constant K
A=K1*(vdes-vcurrent)*normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
K1 can be set to 1/T
(T is in secs)
Meaning of T?
P
T
λ
ddz
dx
Maxim Likhachev Carnegie Mellon University 34
Dynamic Arrive Behavior
• Approach a target point T
if d < arrival radius then vdes=0
else vdes=K*d for some constant K
A=K1*(vdes-vcurrent)*normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
from “Artificial Intelligence for Games” by I. Millington & J. Funge
Maxim Likhachev Carnegie Mellon University 35
Dynamic Arrive Behavior
• Approach a target point T
if d < arrival radius then vdes=0
else vdes=K*d for some constant K
A=K1*(vdes-vcurrent)*normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
http://www.red3d.com/cwr/steer/Arrival.html
Maxim Likhachev Carnegie Mellon University 36
Dynamic Arrive Behavior
• Approach a target point T
if d < arrival radius then vdes=0
else vdes=K*d for some constant K
A=K1*(vdes-vcurrent)*normalize([dx,dz])
ddΨ=K(Ψ-λ-π) limited by max. angular acceleration
compute motion
direction
How would you
implement
velocity matching
behavior?
Maxim Likhachev Carnegie Mellon University 37
Dynamic Pursue Behavior
• Pursue a moving target T that isn’t closecompute motion
direction
P
T
λ
ddz
dx
T T … T
Where will seek
direct the
character?What’s the
problem? Solutions?
Maxim Likhachev Carnegie Mellon University 38
Dynamic Pursue Behavior
• Pursue a moving target T that isn’t close
seek with target position at:
d/vcurrent*VT
compute motion
direction
P
T
λ
ddz
dx
T T … T
Where will pursue
direct the
character?
Maxim Likhachev Carnegie Mellon University 39
Dynamic Evade Behavior
• Evade a moving target T that isn’t close
flee with target position at:
d/vcurrent*VT
compute motion
direction
P
T
λ
ddz
dx
T T … T
Maxim Likhachev Carnegie Mellon University 40
Dynamic Evade Behavior
• Evade a moving target T that isn’t close
flee with target position at:
d/vcurrent*VT
compute motion
direction
http://www.red3d.com/cwr/steer/PursueEvade.html