300 likes | 433 Views
This chapter from the University of Cologne's course on visual programming and 3D simulation explores the basics of character movement in AI for games. It discusses kinematic and dynamic movement strategies, including steering behaviors such as seeking, fleeing, and wandering. Important concepts like forces, acceleration, and post-processing for actuation are highlighted. The chapter provides code examples and algorithms for implementing these movement techniques, emphasizing practical applications in game development.
E N D
ArtificialIntelligence (forgames)Chapter 3: Movement Universität zu Köln Historisch Kulturwissenschaftliche Informationsverarbeitung WS 12/13 Übung: Visuelle Programmierung I – Simulation und 3D Programmierung Prof. Dr. Manfred Thaller Referent: Jan Moritz Kohl
Die Basics • Kinematisch • Input: position (character + target) + orientation • output: direction + velocity • Dynamisch „Steeringbehaviors“ • input:velocity + position, • outpout:forces + accelerations • flocking
Independent Facing # update position and orientation # and the velocity and rotation position += velocity * time velocity += steering.linear * time orientation += rotation * time rotation += steering.angular * time
Kräfte und Antrieb • Kraft führt zu Änderung der kinetischen Energie • Beschleunigung abhängig von Trägheit • steering algorithmen haben Beschleunigung als output -> post-processing: actuation (Antrieb)
Kinematische Bewegung (Seek) voidKinematicSeek::getSteering(SteeringOutput* output) const { // First work out thedirection output->linear = *target; output->linear -= character->position; // Ifthereisnodirection, do nothing if(output->linear.squareMagnitude() > 0) { output->linear.normalise(); output->linear *= maxSpeed; } }
Kinematische Bewegung (Flee) voidKinematicSeek::getSteering(SteeringOutput* output) const { // First work out the direction output->linear = character->position; output->linear -= *target; // If there is no direction, do nothing if (output->linear.squareMagnitude() > 0) { output->linear.normalise(); output->linear *= maxSpeed; } }
Kinematische Bewegung (Arriving) voidKinematicArrive::getSteering(SteeringOutput* output) const { // First work out thedirection output->linear = *target; output->linear -= character->position; // Ifthereisnodirection, do nothing if(output->linear.squareMagnitude() < radius*radius) { output->linear.clear(); } else { // We'dliketoarrive in timeToTargetseconds output->linear *= ((real)1.0 / timeToTarget); // Ifthatistoo fast, thenclipthespeed if (output->linear.squareMagnitude() > maxSpeed*maxSpeed) { output->linear.normalise(); output->linear *= maxSpeed; } } }
Kinematische Bewegung (Wandering) • Bewegung erfolgt sukzessiv (schlendern) • randomBinomial() funktion liefert Wert zwischen -1 und 1 Werte um 0 sind wahrscheinlicher
Steering Behaviors • Speed ist jetzt acceleration • Problem: Orbit • Lösung: target Radius slow Radius
Steering (Align) radian(-,)
DelegatedBehaviors: PursueandEvade Face Lookingwhereyou‘regoing Wander Path Following Separation Collision
Pursue and Evade ifspeed <= distance /maxPrediction: prediction:maxPrediction
Face / Looking where you‘re going • Delegation der Alignmethode • Character schaut nicht zwingend in die Richtung des target #Check for a zerodirection, andmakenochangeif so ifcharacter.velocity.length() == 0: return #Otherwisesetthetargetbased on thevelocity target.orientation = atan2(-character.velocity.x, character.velocity.z) #2. Delegatetoalign returnAlign.getSteering()
Wander • Zielloses umherwandern • delegated face behavior
Path Following • „Chase the rabbit“
Separation • Linear separation: strength = maxAcceleration * (threshold – distance) / threshold • Inverse squarelaw(Abstandsgesetz): strenght = min(k / (distance * distance), maxAcceleration) „repulsionsteering“
Source Code und Demo unter: www.ai4g.com Millington, Ian/Funge, John: Artificial Intelligence. For Games.Burlington, Massachusetts 2009.