autonomous movement
play

Autonomous Movement IMGD 4000 With material from: - PDF document

3/27/17 Autonomous Movement IMGD 4000 With material from: Millington and Funge, Ar#ficial Intelligence for Games , Morgan Kaufmann 2009 (Chapter 3),


  1. 3/27/17 ¡ Autonomous ¡Movement ¡ IMGD ¡4000 ¡ With ¡material ¡from: ¡ ¡Millington ¡and ¡Funge, ¡ Ar#ficial ¡ Intelligence ¡for ¡Games , ¡ ¡Morgan ¡Kaufmann ¡ ¡2009 ¡(Chapter ¡3), ¡ Buckland, ¡ Programming ¡Game ¡AI ¡by ¡Example , ¡Wordware ¡ 2005 ¡(Chapter ¡3), ¡ ¡hMp://opensteer.sourceforge.net ¡and ¡ hMp://gamedevelopment.tutsplus.com/series/ understanding-­‑steering-­‑behaviors-­‑-­‑gamedev-­‑12732 ¡ ¡ IntroducQon ¡ • Fundamental ¡requirement ¡in ¡many ¡games ¡is ¡to ¡move ¡ characters ¡(player ¡avatar ¡and ¡NPC’s) ¡around ¡realisQcally ¡and ¡ pleasantly ¡ • For ¡some ¡games ¡(e.g., ¡FPS) ¡realisQc ¡NPC ¡movement ¡is ¡preMy ¡ much ¡core ¡(along ¡with ¡shooQng) ¡ à ¡there ¡is ¡no ¡higher ¡level ¡ decision ¡making! ¡ • At ¡other ¡extreme ¡(e.g., ¡chess), ¡no ¡“movement” ¡per ¡se ¡ à ¡ pieces ¡just ¡placed ¡ Note: ¡as ¡for ¡pathfinding, ¡we’re ¡going ¡to ¡treat ¡everything ¡in ¡2D, ¡ since ¡most ¡game ¡moQon ¡in ¡gravity ¡on ¡surface ¡(i.e., ¡2 ¡½ ¡D) ¡ 2 ¡ 1 ¡

  2. 3/27/17 ¡ Craig ¡Reynolds ¡ Website: ¡hMp://www.red3d.com/cwr/ ¡ ¡ ¡ • The ¡“giant” ¡in ¡this ¡area ¡– ¡his ¡influence ¡cannot ¡be ¡ overstated ¡ – 1987 : ¡“Flocks, ¡Herds ¡and ¡Schools: ¡A ¡Distributed ¡ Behavioral ¡Model,” ¡ Computer ¡Graphics ¡ – 1998 : ¡Winner ¡of ¡ Academy ¡Award ¡in ¡ScienQfic ¡and ¡ Engineering ¡category ¡ • ¡RecogniQon ¡of ¡“his ¡pioneering ¡contribuQons ¡to ¡the ¡ development ¡of ¡three-­‑dimensional ¡computer ¡animaQon ¡for ¡ moQon ¡picture ¡producQon” ¡ – 1999 : ¡“Steering ¡Behaviors ¡for ¡Autonomous ¡Characters,” ¡ Proc. ¡Game ¡Developers ¡Conference ¡ – Lef ¡U.S. ¡R&D ¡group ¡of ¡ Sony ¡Computer ¡Entertainment ¡ in ¡ April ¡2012 ¡afer ¡13 ¡years ¡ – Now ¡(2015) ¡at ¡ SparX ¡(eCommerce ¡coding ¡within ¡ Staples ) ¡ 3 ¡ Outline ¡ • IntroducQon ¡ ¡ ¡ ¡(done) ¡ • The ¡“Steering” ¡Model ¡ ¡(next) ¡ ¡ • Steering ¡Methods ¡ • Flocking ¡ • Combining ¡Steering ¡Forces ¡ 2 ¡

  3. 3/27/17 ¡ The ¡“Steering” ¡Model ¡ Choosing ¡goals ¡and ¡plans, ¡e.g. ¡ Ac'on ¡Selec'on ¡ • ¡“go ¡here” ¡ • ¡ ¡“do ¡A, ¡B, ¡and ¡then ¡C” ¡ Calculate ¡trajectories ¡to ¡saQsfy ¡goals ¡and ¡ Steering ¡ plans ¡ Produce ¡steering ¡force ¡that ¡determines ¡ where ¡and ¡how ¡fast ¡character ¡moves ¡ ¡ Mechanics ¡(“how”) ¡of ¡moQon ¡ Locomo'on ¡ • ¡Differs ¡for ¡characters, ¡e.g., ¡fish ¡vs. ¡ horse ¡(e.g., ¡compare ¡animaQons) ¡ • ¡Independent ¡of ¡steering ¡ 5 ¡ The ¡“Steering” ¡Model ¡– ¡Example ¡ ¡ • Cowboys ¡tend ¡herd ¡of ¡caMle ¡ • Trail ¡boss ¡decision ¡ represents ¡acQon ¡ • Cow ¡wanders ¡away ¡ – Observes ¡world ¡– ¡ cow ¡is ¡ • Trail ¡boss ¡tells ¡cowboy ¡to ¡ missing ¡ fetch ¡stray ¡ – Selng ¡goal ¡– ¡ retrieve ¡cow ¡ • Cowboy ¡says ¡“giddy-­‑up” ¡ • Steering ¡done ¡by ¡cowboy ¡ and ¡guides ¡horse ¡to ¡cow, ¡ – Go ¡faster, ¡slower, ¡turn ¡right, ¡ avoiding ¡obstacles ¡ leE ¡ … ¡ • Horse ¡implements ¡ locomoQon ¡ – With ¡signal, ¡go ¡in ¡indicated ¡ Note, ¡depending ¡upon ¡the ¡ direcQon ¡ game, ¡player ¡could ¡control ¡ – Account ¡for ¡mass ¡when ¡ boss ¡or ¡cowboy ¡(or ¡both)! ¡ acceleraQng/turning ¡ – Provide ¡animaQon ¡ 3 ¡

  4. 3/27/17 ¡ AcQon ¡SelecQon ¡ • Done ¡through ¡variety ¡of ¡means… ¡ – e.g., ¡ decision ¡tree ¡ or ¡ FSM ¡ – (see ¡earlier ¡slide ¡deck) ¡ Ac'on ¡Selec'on ¡ • Examples: ¡ – “Get ¡health ¡pack” ¡ – “Charge ¡at ¡enemy” ¡ • Player ¡input ¡ – “Return ¡to ¡base” ¡ – “Fetch ¡cow” ¡ LocomoQon ¡ Dynamics ¡ Locomo'on ¡ class Body // Point mass of rigid body // ¡Scale ¡vector ¡to ¡appropriate ¡size ¡(max) ¡ mass // scalar vector ¡truncate(vector ¡v, ¡int ¡ ¡max) ¡{ ¡ ¡ ¡float ¡f; ¡ position // vector ¡ ¡f ¡= ¡ ¡max ¡/ ¡v.getLength(); ¡ velocity // vector ¡ ¡if ¡(f ¡< ¡1.0) ¡ ¡ ¡ ¡ ¡f ¡= ¡1.0 ¡ // Orientation of body ¡ ¡v.scaleBy(f); ¡ heading // vector ¡ ¡return ¡v; ¡ } ¡ // Dynamic properties of body maxForce // scalar maxSpeed // scalar def update (dt) { force = ...; // Combine forces from steering behaviors acceleration = force / mass; // Update acceleration w/Newton's 2nd law velocity += truncate ( acceleration * dt, maxSpeed ); // Update speed position += velocity * dt; // Update position if ( | velocity | > 0.000001 ) // If vehicle moving enough heading = normalize ( velocity ); // Update heading to velocity vector // render … } 8 ¡ 4 ¡

  5. 3/27/17 ¡ Individual ¡Steering ¡“Behaviors” ¡ Compute ¡forces ¡ seek flee arrive pursue Steering ¡ wander evade interpose hide avoid obstacles follow path MulQple ¡behaviors ¡combine ¡forces ¡(e.g., ¡ flocking ) ¡ 9 ¡ So ¡“Steering” ¡in ¡this ¡Context ¡Means ¡ Making ¡objects ¡move ¡by: ¡ • Applying ¡forces ¡ instead ¡of ¡ • Directly ¡transforming ¡their ¡posiQons ¡ Why? ¡ • ...because ¡it ¡looks ¡much ¡more ¡natural ¡ i.e., ¡“steering” ¡does ¡not ¡mean ¡just ¡using, ¡say, ¡the ¡arrow/WASD ¡keys ¡to ¡ move ¡an ¡avatar, ¡but ¡doing ¡moQon ¡by ¡ applying ¡forces ¡ 10 ¡ 5 ¡

  6. 3/27/17 ¡ Adding ¡Forces ¡in ¡UE4 ¡ Add ¡force ¡to ¡a ¡single ¡rigid ¡body ¡ virtual ¡void ¡AddForce ¡(Fvector ¡Force, ¡Fname ¡BoneName) ¡ – Force ¡– ¡force ¡vector ¡to ¡apply. ¡ ¡Magnitude ¡is ¡ strength ¡of ¡force ¡ – BoneName ¡– ¡name ¡of ¡body ¡to ¡apply ¡it ¡to ¡(‘None’ ¡ to ¡apply ¡to ¡root ¡body) ¡ void ¡AMyCharacter::AddUpwardForce() ¡{ ¡ ¡ ¡ ¡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 ¡ cen#meters ¡ C++ ¡ Blueprints ¡ Note: ¡ max ¡velocity ¡ property ¡of ¡object ¡ i.e., ¡earth ¡gravity ¡981 ¡cm/s 2 ¡ Steering ¡Methods ¡ class Body { def update (dt) { combineForces(); // combine forces from steering behaviors … } • Forces ¡returned ¡by ¡each ¡ def seek (target) { ... return force; } method ¡are ¡combined ¡ def flee (target) { ... return force; } (shown ¡later) ¡ def arrive (target) { ... return force; } def pursue (body) { ... return force; } • Individual ¡behaviors ¡can ¡ def evade (body) { ... return force; } be ¡turned ¡on/off ¡(next ¡ def hide (body) { ... return force; } slide) ¡ def interpose (body1, body2) { return force: } def wander () { ... return force; } def avoidObstacles () { ... return force; } ... }; 12 ¡ 6 ¡

  7. 3/27/17 ¡ Turning ¡Steering ¡Methods ¡On ¡& ¡Off ¡ • AcQon ¡SelecQon ¡controls ¡which ¡steering ¡ behaviors ¡on/off ¡ class ¡Body ¡{ ¡ ¡ private: ¡ vector ¡Body::combineForces() ¡{ ¡ ¡ ¡bool ¡seek_on; ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡( ¡doSeek() ¡) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ force ¡+= ¡seek(); ¡ public: ¡ ¡ ¡ ¡ ¡ ¡ ¡… ¡ ¡ ¡void ¡setSeek(bool ¡on=true); ¡ } ¡ ¡ ¡bool ¡doSeek(); ¡ ¡ ¡… ¡ } ¡ 13 ¡ Reference ¡Code ¡in ¡C++ ¡ • Complete ¡example ¡code ¡for ¡this ¡unit ¡from ¡ Buckland’s ¡book ¡can ¡be ¡downloaded ¡from: ¡ hMp://samples.jbpub.com/9781556220784/Buckland_SourceCode.zip ¡ – Folder ¡for ¡Chapter ¡3 ¡ • See ¡also ¡learning ¡guide’s ¡“Understanding ¡ Steering ¡Behaviors”: ¡ hMp://gamedevelopment.tutsplus.com/series/understanding-­‑steering-­‑ behaviors-­‑-­‑gamedev-­‑12732 ¡ ¡ – Similar ¡concepts, ¡slightly ¡different ¡code ¡ implementaQon ¡ ¡ 14 ¡ 7 ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend