DM842 Computer Game Programming: AI Lecture 3
Movement Behaviors
Marco Chiarandini
Department of Mathematics & Computer Science University of Southern Denmark
Movement Behaviors Marco Chiarandini Department of Mathematics - - PowerPoint PPT Presentation
DM842 Computer Game Programming: AI Lecture 3 Movement Behaviors Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark Outline 1. Combined Steering Blending Priorities Cooperative Arbitration
Department of Mathematics & Computer Science University of Southern Denmark
2
3
4
5
7
class BlendedSteering: behaviors # list of behavior and weight maxAcceleration maxRotation def getSteering(): steering = new Steering() for behavior in behaviors: steering += behavior.weight ∗ behavior.getSteering() steering.linear = max(steering.linear, maxAcceleration) steering.angular = max(steering.angular, maxRotation) return steering
8
9
10
class PrioritySteering: groups # list of BlendedSteering instances epsilon def getSteering(): for group in groups: steering = group.getSteering() if steering.linear.length() > epsilon or abs(steering.angular) > epsilon: return steering return steering
12
13
15
17
class SteeringPipeline: targeters decomposers constraints actuator constraintSteps deadlock kinematic # current kinematic data for the character def getSteering(): goal # top level goal for targeter in targeters: goal.updateChannels(targeter.getGoal(kinematic)) for decomposer in decomposers: goal = decomposer.decompose(kinematic, goal) validPath = false for i in 0..constraintSteps: path = actuator.getPath(kinematic, goal) for constraint in constraints: if constraint.isViolated(path): goal = constraint.suggest(path, kinematic, goal) break continue return actuator.output(path, kinematic, goal) return deadlock.getSteering()
18
19
20
21
22
23
24
25
26
27
28
ys2 m − 2gy(py0 − pyt)
30
i
i
i
x + u2 y + u2 z
i − 4(g · ∆ + s2 m)t2 i + 4|∆|2 = 0,
i
31
t = g − kp′ t − cp′ t|p′ t|
32
33
34
35
36
2gyt2
−vy ±√ 2g(Ey −Sy )+v 2
y
g
t
t
37
class Jump (VelocityMatch): jumpPoint canAchieve = False maxSpeed maxYVelocity def getSteering(): if not target: target = calculateTarget() if not canAchieve: # hence no steering towards target return new SteeringOutput() if character.position.near(target.position) and character.velocity.near(target.velocity): # we jump hence no steeering scheduleJumpAction() return new SteeringOutput() return VelocityMatch.getSteering()
def calculateTarget(): target = new Kinematic() target.position = jumpPoint.jumpLocation sqrtTerm = sqrt(2∗gravity.y∗jumpPoint. deltaPosition.y + maxYVelocity∗ maxVelocity) time = (maxYVelocity − sqrtTerm) / gravity.y # 1st if not checkJumpTime(time): time = (maxYVelocity + sqrtTerm) / gravity.y # 2nd checkJumpTime(time) def checkJumpTime(time): vx = jumpPoint.deltaPosition.x / time vz = jumpPoint.deltaPosition.z / time speedSq = vx∗vx + vz∗vz if speedSq < maxSpeed∗maxSpeed: target.velocity.x = vx target.velocity.z = vz canAchieve = true return canAchieve
38
39
40
41
42
43
s =
44
si = psi − pc
45
def updateSlots(): anchor = getAnchorPoint()
for i in 0..slotAssignments.length(): relativeLoc = pattern.getSlotLocation(slotAssignments[i].slotNumber) location = new Static() location.position = relativeLoc.position ∗ orientationMatrix + anchor.position location.orientation = anchor.orientation + relativeLoc.orientation location.position −= driftOffset.position location.orientation −= driftOffset.orientation slotAssignments[i].character.setTarget(location)
46
class DefensiveCirclePattern: characterRadius def calculateNumberOfSlots(assignments): filledSlots = 0 for assignment in assignments: if assignment.slotNumber >= maxSlotNumber: filledSlots = assignment.slotNumber numberOfSlots = filledSlots + 1 return numberOfSlots def getDriftOffset(assignments): center = new Static() # center of mass for assignment in assignments: location = getSlotLocation(assignment. slotNumber) center.position += location.position center.orientation += location.
numberOfAssignments = assignments. length() center.position /= numberOfAssignments center.orientation /= numberOfAssignments return center
def getSlotLocation(slotNumber): angleAroundCircle = slotNumber / numberOfSlots ∗ PI ∗ 2 # The radius depends on the radius
# and the number of characters in the circle: # we want there to be no gap between character’s shoulders. radius = characterRadius / sin(PI / numberOfSlots) # Create a location, and fill its components based # on the angle around circle. location = new Static() location.position.x = radius ∗ cos( angleAroundCircle) location.position.z = radius ∗ sin( angleAroundCircle) # The characters should be facing out location.orientation = angleAroundCircle return location
47
48
49
j∈A(i) 1/(1 + cij), cij is slot cost for agent
50
51
52
53