introduction
play

Introduction Fundamental requirement in many games is to move - PDF document

3/31/2016 Introduction Fundamental requirement in many games is to move characters (player avatar and NPCs) around realistically and pleasantly Autonomous Movement For some games (e.g., FPS) realistic NPC movement is pretty much core


  1. 3/31/2016 Introduction • Fundamental requirement in many games is to move characters (player avatar and NPC’s) around realistically and pleasantly Autonomous Movement • For some games (e.g., FPS) realistic NPC movement is pretty much core (along with shooting) � there is no higher level decision making! IMGD 4000 • At other extreme (e.g., chess), no “movement” per se � pieces just placed With material from: Millington and Funge, Artificial Intelligence for Games , Morgan Kaufmann 2009 (Chapter 3), Note: as for pathfinding, we’re going to treat everything in 2D, Buckland, Programming Game AI by Example , Wordware 2005 (Chapter 3), http://opensteer.sourceforge.net and since most game motion in gravity on surface (i.e., 2 ½ D) http://gamedevelopment.tutsplus.com/series/understanding -steering-behaviors--gamedev-12732 2 Craig Reynolds Outline Website: http://www.red3d.com/cwr/ • The “giant” in this area – his influence cannot be • Introduction (done) overstated – 1987 : “Flocks, Herds and Schools: A Distributed • The “Steering” Model (next) Behavioral Model,” Computer Graphics • Steering Methods – 1998 : Winner of Academy Award in Scientific and Engineering category • Flocking • Recognition of “his pioneering contributions to the development of three-dimensional computer animation for • Combining Steering Forces motion picture production” – 1999 : “Steering Behaviors for Autonomous Characters,” Proc. Game Developers Conference – Left U.S. R&D group of Sony Computer Entertainment in April 2012 after 13 years – Now (2015) at SparX (eCommerce coding within Staples ) 3 The “Steering” Model The “Steering” Model – Example • Cowboys tend herd of cattle • Trail boss decision Choosing goals and plans, e.g. Action Selection represents action • Cow wanders away • “go here” – Observes world – cow is • Trail boss tells cowboy to missing • “do A, B, and then C” fetch stray – Setting goal – retrieve cow • Cowboy says “giddy-up” and Calculate trajectories to satisfy goals and • Steering done by cowboy Steering guides horse to cow, plans – Go faster, slower, turn right, avoiding obstacles left … Produce steering force that determines • Horse implements where and how fast character moves locomotion Mechanics (“how”) of motion Locomotion – With signal, go in indicated Note, depending upon the • Differs for characters, e.g., fish vs. direction game, player could control horse (e.g., compare animations) – Account for mass when boss or cowboy (or both)! accelerating/turning • Independent of steering – Provide animation 5 1

  2. 3/31/2016 Action Selection Locomotion Dynamics Steering Locomotion • Done through variety of means… class Body // Point mass of rigid body // Scale vector to appropriate size (max) – e.g., decision tree or FSM vector truncate(vector v, int max) { mass // scalar float f; position // vector f = max / v.getLength(); – (see earlier slide deck) velocity // vector if (f < 1.0) Action Selection f = 1.0 • Examples: // Orientation of body v.scaleBy(f); heading // vector return v; } – “Get health pack” // Dynamic properties of body maxForce // scalar – “Charge at enemy” maxSpeed // scalar • Player input def update (dt) { force = ...; // Combine forces from steering behaviors acceleration = force / mass; // Update acceleration w/Newton's 2nd law – “Return to base” velocity += truncate ( acceleration * dt, maxSpeed ); // Update speed position += velocity * dt; // Update position – “Fetch cow” if ( | velocity | > 0.000001 ) // If vehicle moving enough heading = normalize ( velocity ); // Update heading to velocity vector // render … } 8 Individual Steering “Behaviors” So “Steering” in this Context Means Compute forces Making objects move by: • Applying forces seek flee instead of arrive pursue Steering • Directly transforming their positions wander evade Why? interpose hide • ...because it looks much more natural avoid obstacles follow path i.e., “steering” does not mean just using, say, the arrow/WASD keys to Multiple behaviors combine forces (e.g., flocking ) move an avatar, but doing motion by applying forces 9 10 Adding Forces in UE4 Steering Methods Add force to a single rigid body class Body { def update (dt) { virtual void AddForce (Fvector Force, Fname BoneName) force = ... // combine forces from steering behaviors … – Force – force vector to apply. Magnitude is } strength of force • Forces returned by each def seek (target) { ... return force; } method are combined def flee (target) { ... return force; } – BoneName – name of body to apply it to (‘None’ (shown later) def arrive (target) { ... return force; } def pursue (body) { ... return force; } • Individual behaviors can to apply to root body) def evade (body) { ... return force; } be turned on/off (next def hide (body) { ... return force; } slide) def interpose (body1, body2) { return force: } void AMyCharacter::AddUpwardForce() { def wander () { ... return force; } def avoidObstacles () { ... return force; } const float ForceAmount = 20000.0f; ... Fvector force(0.0f, 0.0f, ForceAmount); }; Fname bone; // defaults to “NAME_None” this->AddForce(force, bone); } Distance units are centimeters C++ Blueprints Note: max velocity property of object 12 i.e., earth gravity 981 cm/s 2 2

  3. 3/31/2016 Turning Steering Methods On & Off Reference Code in C++ • Complete example code for this unit from • Action Selection controls which steering Buckland’s book can be downloaded from: behaviors on/off http://samples.jbpub.com/9781556220784/Buckland_SourceCode.zip – Folder for Chapter 3 class Body { • See also learning guide’s “Understanding private: Steering Behaviors”: vector Body::calcForce() { bool seek_on; if ( doSeek() ) { http://gamedevelopment.tutsplus.com/series/understanding-steering- force += seek(); public: … behaviors--gamedev-12732 void setSeek(bool on=true); } bool doSeek(); – Similar concepts, slightly different code … implementation } 13 14 Seek: Steering Force Outline Note: treat position as a target vector (direction is ignored) • Introduction (done) velocity • The “Steering” Model (done) desired velocity • Steering Methods (next) • Flocking • Combining Steering Forces steering force def seek (target) { // vector from here to target scaled by maxSpeed Will result in smooth path! desired = truncate ( target - position, maxSpeed ); // return steering force DEMO return desired - velocity; // vector difference } (Force: INS/DEL, Speed: HOME/END) 16 Problem with Seek? Problem with Seek • What happens when reaches target? • What happens when reaches target? – Overshoots target • How bad is it? • How bad is it? – Amount of overshoot determined by ratio of maxSpeed to maximum force applied • Intuitively, should decelerate as gets closer to target � Arrive 17 18 3

Recommend


More recommend