Вы находитесь на странице: 1из 40

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
at v t v
v t v at
dt
dt
dv
adt
dt
dv
a
t t
0
0
0 0
) (
) (
2
0 0
0
2
0
0
0
0
0 0
2
1
) (
) (
2
1
) ( ) (
at t v P t P
P t P at t v
P t P dt at v
dt
dt
dP
vdt
dt
dP
v
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
0 0
0
2
0
0
0
0
0 0
2
1
) (
) (
2
1
) ( ) (
at t v P t P
P t P at t v
P t P dt at v
dt
dt
dP
vdt
dt
dP
v
t
t t
same derivation for
orientation and angular
speed d
compute motion
velocity
at v t v
v t v at
dt
dt
dv
adt
dt
dv
a
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]t
2
d[t+1] = d[t] + dd[t]t
[t+1] = [t] + d[t]t + 0.5dd[t]t
2
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

d
dz
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?
d
dz
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

d
dz
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 v
des
=0
else v
des
=K*d for some constant K
A=K
1
*(v
des
-v
current
)*normalize([dx,dz])
dd=K(--) limited by max. angular acceleration
compute motion
direction
K
1
can be set to 1/T
(T is in secs)
Meaning of T?
P
T

d
dz
dx
Maxim Likhachev Carnegie Mellon University 34
Dynamic Arrive Behavior
Approach a target point T
if d < arrival radius then v
des
=0
else v
des
=K*d for some constant K
A=K
1
*(v
des
-v
current
)*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 v
des
=0
else v
des
=K*d for some constant K
A=K
1
*(v
des
-v
current
)*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 v
des
=0
else v
des
=K*d for some constant K
A=K
1
*(v
des
-v
current
)*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 isnt close
compute motion
direction
P
T

d
dz
dx
T T

T
Where will seek
direct the
character?
Whats the
problem?
Solutions?
Maxim Likhachev Carnegie Mellon University 38
Dynamic Pursue Behavior
Pursue a moving target T that isnt close
seek with target position at:
d/v
current
*V
T
compute motion
direction
P
T

d
dz
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 isnt close
flee with target position at:
d/v
current
*V
T
compute motion
direction
P
T

d
dz
dx
T T

T
Maxim Likhachev Carnegie Mellon University 40
Dynamic Evade Behavior
Evade a moving target T that isnt close
flee with target position at:
d/v
current
*V
T
compute motion
direction
http://www.red3d.com/cwr/steer/PursueEvade.html

Вам также может понравиться