CP2: Chase and Flee AI – Simulation in p5.js
Channel: Jeff Thompson
Date: 30/03/2021

While there is a ton of really cool work on games and AI, the tech is really complicated and mathy. This example shows a VERY basic chase and flee behavior. The p5.js vector object simplifies a lot of this math for us. We can calculate the direction an entity should move towards another by subtracting their positions, calculate the distance between two vectors, and even use those values to move an entity in a particular direction! For more ideas, see Valentino Braitenberg's "vehicles", which do things like seek light and hide from each other: http://en.wikipedia.org/wiki/Braitenberg_vehicle

👩‍💻 https://editor.p5js.org/jeffThompson/sketches/o2nlBRPqj

ALL THE VIDEOS IN THIS UNIT
🎥 https://youtube.com/playlist?list=PLsGCUnpinsDkhWlWYUdMC1R2yOLO2Xmqd

SEE ALSO
💡 https://gamedevelopment.tutsplus.com/series/understanding-
  steering-behaviors--gamedev-12732
💡 https://www.gamasutra.com/blogs/JuanBelonPerez/20140724/221421/Introduction_to_Steering_Behaviours.php
💡 https://natureofcode.com/book/chapter-6-autonomous-agents

CHALLENGES
❓ Our chase ball bounces around when it hits you. Can you stop that behavior by checking if it's position is within the player's circle, and not updating if that's true?
❓ Can you make the chase ball turn to face the player? Use a shape like a triangle and vector's angleBetween() function. Hint: you'll need to use push/pop() too.
❓ Can you make the fleeing ball move faster or slower the close we get to it?