DM810 Computer Game Programming II: AI Lecture 4 Movement Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark
Predicting Physics Jumping Coordinated Movement Resume Motor Control Kinematic Movement Delegated Steering Seek Pursue and Evade Wandering Face Steering Movement Looking Where You Are Going Variable Matching Wander Seek and Flee Path Following Arrive Separation Align Collision Avoidance Velocity Matching Obstacle and Wall Avoidance Combined Steering Blending Priorities Cooperative Arbitration Steering Pipeline 2
Predicting Physics Jumping Coordinated Movement Outline Motor Control 1. Predicting Physics Firing Solutions 2. Jumping 3. Coordinated Movement 4. Motor Control 3
Predicting Physics Jumping Coordinated Movement Outline Motor Control 1. Predicting Physics Firing Solutions 2. Jumping 3. Coordinated Movement 4. Motor Control 4
Predicting Physics Jumping Coordinated Movement Predicting Physics Motor Control Needs for physics simulation: current position of a ball and move to intercept the ball character correctly calculating the best way to throw a ball so that it reaches a teammate who is running. where to stay to minimize chance of being hit by a grenade shoot accurately, and respond to incoming fire predicting trajectories 5
Predicting Physics Jumping Coordinated Movement Firing Solution Motor Control Projectile trajectory p t = p 0 + u t s m t + g t 2 2 s m muzzle velocity (speed at which the projectile left the weapon) u t is the direction the weapon was fired g = − 9 . 81ms − 1 but in games about the double is used Predicting a Landing Spot � p x 0 + u x s m t i u 2 y s 2 − u i s m ± m − 2 g y ( p y 0 − p yt ) t i = p y = p y 0 g y p z 0 + u z s m t i 7
Predicting Physics Jumping Coordinated Movement Firing Solution Motor Control Given a target a point E , a firing point S and s m (may be varied too, eg, with grenades) we want to know the firing direction u , | u | = 1 . S x + u x s m t i + 1 2 g x t 2 E x = i S y + u y s m t i + 1 2 g y t 2 E y = i S z + u z s m t i + 1 2 g z t 2 E z = i u 2 x + u 2 y + u 2 1 = z four eq. in four unknowns, leads to: i + 4 | ∆ | 2 = 0 , | g | 2 t 4 i − 4( g · ∆ + s 2 m ) t 2 ∆ = E − S solve in t , and get two solutions u = 2 ∆ − g t 2 i typically choose the lower one 2 s m t i 8
Predicting Physics Jumping Coordinated Movement Drag: Air Resistance Motor Control The path is not anymore a parabola Highly simplified: the drag force can be described as: D = − kv − cv 2 , v velocity of projectile and k, c are parameters. Equation of motion is non linear differential equation p ′′ t = g − k p ′ t − c p ′ t | p ′ t | iterative method via simulation, alternatively, removing second term we can solve p t = g t − A e − kt A = s m u − g B = p 0 − A + B , k , k k 9
Predicting Physics Jumping Coordinated Movement Iterative Targeting Technique Motor Control We wish to solve the firing solution controlling its accuracy to make sure we can hit small or large objects correctly. start with a tentative direction simulate real projectile motion by a physics system continue guessing until within a radius from target To guess one can use the equations without drag or the one with drag simplified. Binary search: find a tentative upper or lower bound, then the opposite bound and continue by binary search. Only possible when the physics engine that can easily set up isolated simulations (ie, different from the current game world) and it is fast enough Moving characters: simplifying assumption constant velocity and direction 10
Predicting Physics Jumping Coordinated Movement Outline Motor Control 1. Predicting Physics Firing Solutions 2. Jumping 3. Coordinated Movement 4. Motor Control 11
Predicting Physics Jumping Coordinated Movement Jumping Motor Control Jumping between a platforms... steering controller needs to check that the character is moving at i) correct speed II) correct direction iii) jump action is executed at the right moment. � Rather complex! Simpler support leaves to the designer the choice of jump points and minimal component velocity in the right direction 12
Predicting Physics Jumping Coordinated Movement Motor Control To carry out the jump the character undergoes the following steps: 1. decide to make a jump by the pathfinding system or a simple steering behavior 2. recognize which jump by pathfinding system or by steering behaviour with lookahead. 3. once found the jump point to use: velocity matching steering behaviour to bring the character into the jump point with correct velocity and direction. 4. once on the jump point, launch a jump action, the game engine will do the rest. 13
Predicting Physics Jumping Coordinated Movement Motor Control Problem resolutions: designer incorporates more information into the jump point data, ie, restrictions on approach velocities (bug prone) designer puts jump points such that the AI cannot fail incorporate in pathfinding landing pads + characters use trajectory prediction to calculate the velocity required to jump from jump point to landing pad + velocity matching v y is upwards velocity of jump and it is given, we wish to find , v x , v z . Three equations in three unknowns − v y ± √ 2 g ( E y − S y )+ v 2 E x = S x + v x t y t = g E y = S y + v y t + 1 2 g y t 2 v x = E x − S x t E z = S z + v z t v z = E z − S z t 14
Predicting Physics Jumping Coordinated Movement Motor Control class Jump (VelocityMatch): def calculateTarget(): jumpPoint target = new Kinematic() canAchieve = False target.position = jumpPoint. maxSpeed jumpLocation maxYVelocity sqrtTerm = sqrt(2*gravity.y*jumpPoint. def getSteering(): deltaPosition.y + if not target: maxYVelocity*maxVelocity) target = calculateTarget() time = (maxYVelocity - sqrtTerm) / if not canAchieve: gravity.y # 1st # hence no steering towards target if not checkJumpTime(time): return new SteeringOutput() time = (maxYVelocity + sqrtTerm) / if character.position.near(target. gravity.y # 2nd position) and checkJumpTime(time) character.velocity.near(target. velocity): def checkJumpTime(time): # we jump hence no steeering vx = jumpPoint.deltaPosition.x / time scheduleJumpAction() vz = jumpPoint.deltaPosition.z / time return new SteeringOutput() speedSq = vx*vx + vz*vz return VelocityMatch.getSteering() if speedSq < maxSpeed*maxSpeed: target.velocity.x = vx target.velocity.z = vz canAchieve = true return canAchieve 15
Predicting Physics Jumping Coordinated Movement Hole Fillers Motor Control jump detector area character leads towards them with a mechanism opposite to well avoidance when the character enters in the area it jumps more flexibility in jumping point no control on the landing point 16
Predicting Physics Jumping Coordinated Movement Outline Motor Control 1. Predicting Physics Firing Solutions 2. Jumping 3. Coordinated Movement 4. Motor Control 17
Predicting Physics Jumping Coordinated Movement Coordinate Movement Motor Control Individuals can 1. make decisions that compliment each other or (bottom up) 2. can make a decision as a whole and move in a prescribed, coordinated group (top down) Formation motion is the movement of a group of characters retaining group organization (under 2) Formation: a set of locations where a character can be positioned. One location is the leader position. 18
Predicting Physics Jumping Coordinated Movement Motor Control Fixed Formations The leader moves independently from formation the others follow with no need for kinematics or steering: p s = p l + s ω s = ω l + ω s but leader needs to take care of the size of the formation when moving Scalable Formations Emergent Formations each character has its own steering system using the arrive behavior. each agent selects as target one of the others agents in the formation (eg, V formation) the formation emerges from the individual rules of each character, like in flocking characters can react individually it may be hard to design rules for the desired shape 19
Predicting Physics Jumping Coordinated Movement Motor Control Two-level formation steering: First level: fixed formation (with a leader that moves it) characters move autonomously avoiding collisions and targetting locations with an arrive behaviour Second level: actually no need for a leader, the formation moves alone around an anchor point steering of anchor points can be simplified, only important obstacles to consider, but speed moderated if agents not in their slots. offset to move a small distance ahead of the center of mass p a = p c + k offset v c p c center of mass of chars p ′ s i = p s i − p c (similarly for velocity and rotation) 20
Predicting Physics Jumping Coordinated Movement Motor Control def updateSlots(): anchor = getAnchorPoint() orientationMatrix = anchor.orientation.asMatrix() 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) 21
Recommend
More recommend