Utrecht University INFOB2KI 2019-2020 The Netherlands ARTIFICIAL INTELLIGENCE Motion Lecturer: Silja Renooij These slides are part of the INFOB2KI Course Notes available from www.cs.uu.nl/docs/vakken/b2ki/schema.html
Outline Move in 2D Individual steering behaviors – Seek, flee, wander – Obstacle avoidance – Jumping Move in 3D
Motion & Kinematics Motion: the action of changing location or position Kinematics : branch of classical mechanics describes motion of points, (systems of) bodies ( (groups of) objects) without consideration of the causes of motion (forces, energies).
Kinematics Kinematic quantities: Position – 2D / 3D vector Orientation – (=‘facing’) radians Velocity – (= speed in direction) 2D / 3D vector Rotation – (= change in orientation) radians In simulation/game: updated each frame
Seek, Flee and Arrive behaviours character: target: + (can be moving as well)
Kinematic Seek character #kinematic data character target #kinematic data target Computations are maxSpeed #maximum speed of character done in each frame! def getSteering(): steering = new KinematicSteeringOutput() steering.velocity = target.position – character.position # direction of target steering.velocity.normalize() steering.velocity *= maxSpeed # full speed in direction character.orientation = getNewOrientation(character.orientation,steering.velocity) # face in direct. of move steering.rotation = 0 return steering
Kinematic Arrive character #kinematic data character target #kinematic data target input Seek maxSpeed #maximum speed of character radius #satisfaction radius (‘found’ target) timeToTarget = 0.25 #goal: get to target in 0.25s input Arrive def getSteering(): steering = new KinematicSteeringOutput() steering.velocity = target.position – character.position if steering.velocity.length() < radius: return None #arrived! steering.velocity /= timeToTarget #speed=distance/time if steering.velocity.length() > maxSpeed: #unless above max steering.velocity.normalize() steering.velocity *= maxSpeed character.orientation = getNewOrientation(character.orientation,steering.velocity) steering.rotation = 0 return steering
Kinematic Wandering Simple implementation: move with max speed in direction of randomly chosen orientation erratic behavior behaviour resembles seeking target in a random spot on a circle surrounding the character: This analogy allows for simple improvements:
Kinematic movement vs Steering Kinematic movement Input: static kinematic data (position,orientation); output velocity and rotation Velocity: speed `on’ or `off’ in target direction Orientation usually in travelling direction; otherwise rotation can be applied Steering behavior Extends kinematic movement by adding changes to velocity and rotation Input: kinematics; output: linear and angular acceleration Variable matching: typically one or more characters’ kinematic matched to target kinematic
Seek & Arrive with acceleration Character # kinematic data character target # kinematic data target input Seek maxAcceleration # maximum acceleration maxSpeed # maximum speed of character targetRadius # satisfaction radius input Arrive slowRadius # radius to slow down timeToTarget = 0.1 # 0.1s to achieve target velocity def getSteering(target): steering = new SteeringOutput() direction = target.position – character.position distance = direction.length() if distance < targetRadius: return None # arrived! if distance > slowRadius: targetSpeed = maxSpeed # move with maxspeed else targetSpeed = maxSpeed * distance / slowRadius # slow down if close targetVelocity = direction targetVelocity.normalize() targetVelocity *= targetSpeed steering.linear = target.position – character.position # only for Seek; remove for Arrive steering.linear = target.velocity – character.velocity # accelerate to target velocity steering.linear /=timeToTarget if steering.linear.length() > maxAcceleration: steering.linear.normalize() steering.linear *= maxAcceleration steering.angular = 0 return steering
Align - Orientation Similar to Arrive with accel.: direction, velocity rotation position orientation distance rotationSize steering.linear steering.angular
Align - Velocity Character # kinematic data character target # kinematic data target maxAcceleration # maximum acceleration maxSpeed # maximum speed of character maxRotation # maximum rotation targetRadius # satisfaction radius slowRadius # radius to slow down # 0.1s to achieve target velocity timeToTarget = 0.1 def getSteering(target): steering = new SteeringOutput() = Arrive with acceleration stripped down to velocity steering.linear = target.velocity – character.velocity steering.linear /=timeToTarget matching… if steering.linear.length() > maxAcceleration: steeringlinear.normalize() Useful in combination with steering.linear *= maxAcceleration other behaviours in e.g. flocking. steering.angular = 0 return steering
More complex behaviors Pursue – predict target’s position, then seek
Follow path: vanilla The whole path is a target and should be followed . ( vanilla) path following: • Find nearest point N on path • Target T = point on path at N + fixed offset • Seek T Multiple options? • Often choose for coherence (new target close to old one)
Follow path: predictive The whole path is a target and should be followed . Predictive path following: • Find nearest point N on path, from predicted future position • Proceed as with vanilla pathfinding • Smoother for complex tasks • Drawback (?): cutting corners
Repulsion or separation Context: keeps characters from getting too close and being crowded character targets threshold # threshold to take action decayCoefficient # constant for decay maxAcceleration def getSteering(): steering = new Steering for target in targets: direction = target.position – character.position distance = direction.length() target is too close if distance < threshold: strength = min(decayCoefficient / (distance ^2), maxAcceleration) #repulsion strength direction.normalize() steering.linear += strength * direction add acceleration return steering
Collision avoidance Concerns collisions with moving targets Simple: Variation of evade/separate; – engaged if target is within cone in front of character Drawback: in-cone doesn’t have to mean collision and vice versa
Collision avoidance Concerns collisions with moving targets Better: Find target closest to collision For each target – Find out if collide (moment of collision) – If collide, find out when and where – Steer away from that target
Obstacle avoidance Use casting rays to find obstacles Multiple Multiple Single rays rays ray Multi-ray problem: “corner trap” Often used solution One ray Two whiskers
Obstacle avoidance State of the art
Combining steering e.g. flocking, swarming,… Weighted blending – Combine steering behavior by computing the weighted sum of all blended behaviors – Problem: equilibria and worse avoid enemy 2 enemy 1 Seek target target result Wall avoidance pursue avoid enemy 1 enemy 2 trapped (do nothing) lost target – Alternatives: prioritize; cooperative arbitration; …
Jumping Jump might fail! (unlike steering) Where to jump? – Jump pads in level – Jumpable holes (design like walls; jump instead of avoid) How to jump? – Need speed, direction and place to start When to jump? – Often determined by path finding
Moving in 3 dimensions More than just one more degree of freedom: Gravity Height of obstacles Stairways Lines of sight Capabilities (jump, fly, …)
Moving in 3 dimensions
Recommend
More recommend