Тёмный

5.3 Flee, Pursue, Evade - The Nature of Code 

The Coding Train
Подписаться 1,7 млн
Просмотров 51 тыс.
50% 1

Continuing my quest to explore all the steering behaviors from Craig Reynolds’ 1999 paper, in this video I tackle flee, pursue, and evade (all in JavaScript with p5.js). Code: thecodingtrain.com/tracks/the...
p5.js Web Editor Sketches:
🕹️ Flee: editor.p5js.org/codingtrain/s...
🕹️ Pursue: editor.p5js.org/codingtrain/s...
🕹️ Evade: editor.p5js.org/codingtrain/s...
🕹️ Pursue Boucing Ball: editor.p5js.org/codingtrain/s...
🕹️ Pursue Wander: editor.p5js.org/codingtrain/s...
🕹️ Pursue Slider Prediction: editor.p5js.org/codingtrain/s...
🎥 Previous video: • 5.2 Seeking a Target -...
🎥 Next video: • 5.4 Arrive Steering Be...
🎥 All videos: • The Nature of Code 2
References:
🔗 Steering Behaviors for Autonomous Characters: www.red3d.com/cwr/steer/
Videos:
🎥 Inheritance in JavaScript: • 16.17: Inheritance in ...
Timestamps:
0:00 Hello Again!
0:12 What's my quest?
1:08 30 seconds on the clock, let's add flee!
1:35 How could we approach this in a smarter way?
3:13 What is pursue?
5:54 We need a the target to be a vehicle.
6:42 Let's add pursue now.
9:12 Now we can add evade!
10:03 What if we pursue and evade?
11:09 Let's refine the pursue example a little.
12:09 What will you make?
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
🚂 Website: thecodingtrain.com/
👾 Share Your Creation! thecodingtrain.com/guides/pas...
🚩 Suggest Topics: github.com/CodingTrain/Sugges...
💡 GitHub: github.com/CodingTrain
💬 Discord: thecodingtrain.com/discord
✪ Nebula: go.nebula.tv/codingtrain
💖 Membership: ru-vid.comjoin
🛒 Store: standard.tv/codingtrain
🖋️ Twitter: / thecodingtrain
📸 Instagram: / the.coding.train
🎥 Coding Challenges: • Coding Challenges
🎥 Intro to Programming: • Start learning here!
🔗 p5.js: p5js.org
🔗 p5.js Web Editor: editor.p5js.org/
🔗 Processing: processing.org
📄 Code of Conduct: github.com/CodingTrain/Code-o...
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
#forbeginners #javascript #p5js

Опубликовано:

 

2 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 86   
@Hermaniac8
@Hermaniac8 3 года назад
Getting in early: Congratulations on finally finishing every steering behavior! And happy new years 2033! 🥳🎉
@Philyshark7
@Philyshark7 2 года назад
@@harshaaddanki4606 whooooosh
@kristoffhowell9871
@kristoffhowell9871 11 месяцев назад
CORRECTION: I love the lesson it helped figuring things out. I do have one correction. Flee is not the negative of seek. the reference article actually had "Implement a “fleeing” steering behavior (desired vector is inverse of “seek”)." so what should have happed so that the desired vector alone should be negative. I took be a while to realize the issue as i was wondering why flee wasn't the opposite of seek. It took me drawing the calculated vectors to realize there is a mistake.
@NickCombs
@NickCombs 3 года назад
Pursuit should probably check further ahead of the target's velocity based on the distance. The longer it takes you to catch up to something, the further it will have travelled.
@TheCodingTrain
@TheCodingTrain 3 года назад
Yes, excellent point!
@ashaygoli3014
@ashaygoli3014 3 года назад
Right. That's why it's generally a tunable parameter called the "lookahead distance".
@WarrenHull
@WarrenHull 3 года назад
I added the following line to the pursue function: let dist = this.pos.dist(target); and then modified the multiplication line as follows: prediction.mult(dist/this.maxSpeed); It gives a pretty nice result.
@sjdpfisvrj
@sjdpfisvrj 3 года назад
I was actually hoping pursuit would be more an "intercept", i.e. the chosen direction would be the one that, assuming the target just continues in the same direction, you would perfectly catch up with it.
@LithiumDeuteride-6
@LithiumDeuteride-6 Год назад
It is better to use proportional guidance, such as is used in homing missiles, for example Strela-2/2M/3, Igla, Red Eye, Stinger, etc.
@nizarch22
@nizarch22 3 года назад
I absolutely love your videos coding train! When I think of learning something new and interesting this is where I go.
@fredoliveira1223
@fredoliveira1223 3 года назад
Thank you for doing what you do, you are doing young coders a great service.
@gyokzoli
@gyokzoli 3 года назад
Dude, never stop making this videos. Just watching you teaching makes me feel much better about humanity.
@dslbit2
@dslbit2 3 года назад
shiffman and Casey Muratori are my programming heroes, thank you for everything
@neillunavat
@neillunavat 3 года назад
I just love this series. Thx for producing some more vids ❤
@fruit5i49
@fruit5i49 3 года назад
damn. you've been doing this for 8 years already. what a legend. keep up the good work man :)
@TSHORYUKEN
@TSHORYUKEN 2 года назад
you are my master ! ur videos are perfect for making shooting game !!
@carlsb3rg
@carlsb3rg 3 года назад
Cool. A nice example would be a target fleeing from a pursuer, perhaps simulating the target getting a random boost of maximum speed as adrenalin kicks in :)
@TheCodingTrain
@TheCodingTrain 3 года назад
Oh, fantastic idea!
@carlsb3rg
@carlsb3rg 3 года назад
@@TheCodingTrain My whole approach is a bit different, but the principles are the same ( kreativitetno.github.io/steering_behavior_p5js/index.html ). Scenario 1 is a fleeer and a seeker and scenario 2 is a pursuer, wanderer and a fraidycat :D I'll try to add a better README.md, but I think my code is pretty readable.
@badunius_code
@badunius_code 2 года назад
Isn't it obvious 😏
@DrNabeel20
@DrNabeel20 2 года назад
Great video as usual ! thanks
@pendragon7600
@pendragon7600 3 года назад
I have a pursuing behavior towards these nature of code videos
@julianabhari7760
@julianabhari7760 3 года назад
Hey Dan, have you ever thought about doing a coding train podcast? I would absolutely love to listen to you talk for hours. You could call it coding off the rails ;)
@arturitoproductions
@arturitoproductions 2 года назад
I love this serie, please pursuit :)
@petervladyevich8535
@petervladyevich8535 3 года назад
Very interesting. Thank you!
@alexlangevin8340
@alexlangevin8340 2 года назад
Love it!
@pvic6959
@pvic6959 3 года назад
the only thing i hate about these videos is that they end :'( im living the steering vids!
@Tweakimp
@Tweakimp 3 года назад
Now make multiple groups A,B,C of vehicles with A persuing B, B persuing C and C persuing A while fleeing from the other :)
@ChaoteLab
@ChaoteLab 3 года назад
Shiffman & Reynolds be like the Starsky & Hutch of creative coding.
@xnick_uy
@xnick_uy 3 года назад
10:47 YES!! I see endless possibilities!! I can almost identify with one of this entities with growing AI, video after video. :-) One possible nuance that can appear down the road in the pursue() function is having a fixed (hard-coded!) multiplier for how much further in the future the vehicle is looking ahead. This can lead to a strange or weird behavior when the pursuer gets very close to the target but then steers away from it, since it seeks for the predicted position (this should become apparent when the target vehicle is moving very slow). Hence, I believe that the multiplier for the target in the pursue function needs to be based on the current distance between the vehicles (larger multiplier when they are far apart, smaller multiplier when they are close).
@xnick_uy
@xnick_uy 3 года назад
tyvm for the
@RajJaiswal538
@RajJaiswal538 3 года назад
I would love seeing an example where the persuer is afraid of the target and only runs away from him when he gets in a certain radius of the target. Other time,the persuer just wanders around.
@pauldedward
@pauldedward 3 года назад
I don't know whether you remember my last comment in a previous video...but yeah...I finally caught up with the NOC 2.0😁...Thanks Dan❣️
@fpinanba
@fpinanba 3 года назад
Nice video, but I think a key aspect that you didn't take into account is that how far ahead the pursuer have to predict the position should depend on the distance to the target. In that case, once the pursuer is approaching the target, the predicted position should not change anymore (unless the target changes its velocity)
@pvbuerkner
@pvbuerkner 3 года назад
I had the same thought. Depending on the angle I feel there is a slight possibility of the pursuer arriving at the predicted target position but actually not touching the target itself. A small oversight
@SimonTiger
@SimonTiger 3 года назад
He already had this kind of question in the seek video, saying he didn't take something into account. What he describes here is what Reynolds came up with with the original set of steering behaviors, but there's nothing saying those are the "correct rules". You can make up your own rules for calculating the desired velocity if you want, and there's nothing stopping you from saying that's a valid behavior.
@TheCodingTrain
@TheCodingTrain 3 года назад
This is a great point! I’ll come back to discuss in a live stream!
@ricksidwell
@ricksidwell 3 года назад
What Simon said! Dan alluded to this in the seek video: "What the desired velocity actually is, that's the tricky question. ...as you make your own behaviors, thinking about what is the entity's desire is incredibly important." This is especially applicable for pursue; you can get a lot of different behaviors using different desires and capabilities. Does the pursuer want to ram the target at maximum speed? Or just gently tag it? What if the pursuer's rear sensors aren't very accurate and can only sense general position, not velocity. What if the pursuer has no sensors in the rear and needs to look around for the target? Can the pursuer track the target's course for some amount of time and use that to predict the future position more accurately (perhaps using polynomial regression or even artificial intelligence)? Can we include knowledge of the wrapping behavior, so it can go up when the target is going down near the bottom edge? Endless possibilities here!
@wellox8856
@wellox8856 3 года назад
Oh hey a new video :D
@annperera6352
@annperera6352 3 года назад
Dan please do some videos on implementing hybrid machine learning models, how to implement collaborative filtering,rule based classification, association rules.
@kevnar
@kevnar 2 года назад
I think the fleeing behavior should have a radius, just like the arrive function. When the danger is within a certain range, flee. When out of that range, ignore it. When the bunny escapes the fox, it doesn't keep running forever.
@martinvivian9772
@martinvivian9772 3 года назад
How far ahead of the target the pursuer looks should be at least somewhat defined by the distance to the target and the pursuers max speed. So probably d/s (distance over speed) such that if your close or fast you look less far ahead, if you are slow or distant you look further ahead.
@viniciusfriasaleite8016
@viniciusfriasaleite8016 3 года назад
As others said, the distance ahead of the target depends to the distance to the target. I wonder what would be the optimal relation
@ronaldsimatupang4621
@ronaldsimatupang4621 3 года назад
Nice👍
@techmuch256
@techmuch256 3 года назад
I believe the argument made by Trevor Sargent is correct. The desired velocity, not the force should be flipped and it does make a big difference. Imagine the target being fleed is directly in front of the vehicle which is moving at maximum speed towards it. The seek function would give you a force of zero because the velocity of the vehicle is the same as the desired seek velocity, but the zero vector flipped is still the zero vector. The correct force should obviously be behind the vehicle though! So, the vehicle would crash into the target before fleeing! On a broader point, this is why I personally don't like steering behaviors, because how it should be done is so ambiguous that mistakes like this can be made easily. As another example, one could argue an actual agent would not move as described by Craig Reynold's rules in the following situation. If fleeing a target to the side of the vehicle (so the vehicle is moving perpendicular to it), the steering force should be directly away, because trying to slow down to match a desired velocity away from the target is a waste of time. The desired velocity would change as the vehicle turns but in this instant of time, it would waste time as its limited force is also trying to slow it down. I hope that makes sense, basically, the goal should be to get anywhere but where the target is, not specifically directly away in this instant.
@TheCodingTrain
@TheCodingTrain 3 года назад
Thank you for this excellent additional information!
@amogus7
@amogus7 3 года назад
-Type this nice CSS into your p5.js projects if you want the canvas to be centered- main { display: flex; height: 100vh; width: 100vw; position: fixed; } main canvas { margin: auto; }
@ajreukgjdi94
@ajreukgjdi94 2 года назад
I was thinking you were going to add a memory of the target's previous position, then use its current position to calculate velocity. Because a true evader shouldn't be able to just read the 'mind' of its pursuer. Or in this case, read its hidden members.
@mrsplike7408
@mrsplike7408 3 года назад
Is it possible to make a pursuit target that's controlled by the user? I can't figure out how the predicted location would work if it's being controlled by the user. Great video!
@wolfrig2000
@wolfrig2000 3 года назад
I found your channel through Nebula, I have to go back and watch some of your earlier videos, I find bots and object recognition really interesting but don't understand what's going on
@gower1973
@gower1973 3 года назад
What is this extends keyword? Is it like class inheritance in c++? I think it would be good if you encapsulated all the steering behaviors into a state machine.
@harshjain4256
@harshjain4256 3 года назад
You can make the target to envade the pursuer and pursuer to pursue the target then it will be like police catching a theif
@badunius_code
@badunius_code 2 года назад
Pursue is essentially a Seek with 0 steps ahead prediction. Same with the Flee and Evade.
@trevorasargent
@trevorasargent 3 года назад
long time listener first time caller
@TheCodingTrain
@TheCodingTrain 3 года назад
Oh gosh this is such a good point / good question! I think it would turn out the same I will have to investigate!
@TheCodingTrain
@TheCodingTrain 3 года назад
Upon further investigation during my live stream, it is MOST DEFINITELY not the same and this is such an error that I plan to record a separate video about this correction. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-zC8GcS6-kNQ.html (if someone can reply with the timecode after it's published that would be great!)
@darkfrei2
@darkfrei2 3 года назад
How to make a train, where the distance between wagons is always same?
@marwans4018
@marwans4018 2 года назад
When you will do obstacle avoidance ?
@georgecolumbu5077
@georgecolumbu5077 Год назад
Hello, I am trying to implement the steering behaviours for my bachelors degree project but when I use the force from seek and multiply it by -1 to create the force for flee it works, but it doesnt seem to take into account maxSpeed and maxForce. Any ideeas why?
@chiptunesfreemusic5040
@chiptunesfreemusic5040 2 года назад
Enseña a crear vectores y como prededicir donde estará un objeto por su velocidad, todo lo del video... pero en javascript nativo, sin la librería P5. gracias (?
@osamamuhammad7962
@osamamuhammad7962 3 года назад
Can you simulate glass crash
@Chris-Brown-
@Chris-Brown- 2 года назад
As you explain them I'm translating them in to a different language
@survivalizeed
@survivalizeed 3 года назад
Damn CodeTrain you are part of the Copilot AI haha. It stole your fleetbattle code xD
@champion6929
@champion6929 Год назад
is it correct using pursuit to achieve evade? Graig says to use flee to achieve evade
@ramij786
@ramij786 3 года назад
please make video on how verify people with verified batch, and how to add audio meeting on website like social media.
@ramongonzalezfernandez8904
@ramongonzalezfernandez8904 3 года назад
Wouldn't the seek(target).mul(-1) not work if it wasn't immediately limited? the seek formula you used is (target-pos)-v while the flee formula is -((target-pos)-v) or -target+pos+v. this gets added on to the velocity v, causing v to be somewhat doubled, except for the (target-pos) subtracted from it, which is limited. This means that as soon as the velocity passes a certain point, it would grow uncontrolably. Instead, the desired vector should be inverted, so that the velocity is still subtracted instead of added.
@monsieuralexandergulbu3678
@monsieuralexandergulbu3678 3 года назад
0:45 clickbait! ;) We want arrival!
@fudgeracoon2529
@fudgeracoon2529 3 года назад
:D
@jordanliebenberg42
@jordanliebenberg42 3 года назад
How can i download p5js.org
@Quidoute
@Quidoute 3 года назад
Can you explain this in vanilla JavaScript?
@CivilF11
@CivilF11 3 года назад
Which part do you want explained exactly? Like, how it works? Or how to implement in javascript without a library?
@tommyplays5436
@tommyplays5436 3 года назад
The vanilla version will require a gameloop, vector functions and understanding of canvas. Try codepen.io for public examples.
@wireghost897
@wireghost897 Год назад
LMAO, even I can't spell Pursuit. Kept using "Persuit"
@alenaalena181
@alenaalena181 2 года назад
I study at the university the computer department, but I do not have a computer, I attend electronic lectures and exams on my mobile. I wish I had a computer, I work to buy it, but it is expensive 😞😞
@mahbubhussain9998
@mahbubhussain9998 3 года назад
Create a word search game using javascript
@kevnar
@kevnar 3 года назад
Why didn't he have the target evade the pursuer!? Ahhhhg!
@TheCodingTrain
@TheCodingTrain 3 года назад
DOH!
@ravindran_1
@ravindran_1 3 года назад
Sir i need ur help i wanna learn how to hack color prediction games plz help
@aaradhyagrawal8759
@aaradhyagrawal8759 3 года назад
ahhh
@AlexIsTripping
@AlexIsTripping 3 года назад
hey does anyone wanna help me with a game
@codenerd7823
@codenerd7823 3 года назад
Took me only 11 seconds
@planktonfun1
@planktonfun1 3 года назад
First
@mandelum
@mandelum 3 года назад
As a longtime fan of your work, I love the quality of these new videos on such a classic and fun topic. But I had to comment just to make a wish that they could just be kept slightly more natural, less cutting, the sped-up typing adds a faster pace, but I actually miss your typing rhythm, and I am sure you already talk plenty fast for many people, your slowness is good, it's just the random numbers and talk that sometimes gets tedious... However this is obviously very personal/contextual. Much love, have been watching since vimeo, and read your books before that. Keep doing fun creative problem solving live! We learn so much from the real-time process... Would be cool to see a series of combination videos, where you combine a few ideas, don't limit yourself with the role of being "just" a teacher, you are an artist, a live explorer, a recreational mathematician, a comedian, a virtual friend, philosopher, blob of fun, happening, etc. Just stay true to your core vibe of creative coding/exploring and surprise yourself. We really appreciate this! Also, listen to Erindale's channel on Blender for comparison with another great slow but thoughtful vibe... Blender which of course it would be lovely to see you explore more live, maybe also with Python and/or Sverchok. Just keep it fun yet challenging. Waiting for the Spring Network with your videos, hope you could make it from scratch with springs even in Processing And one day maybe try oFx, cinder, juce or some other high-performance framework in C++ or Swift/Metal one day, for me performance is often a bottleneck in both js and Processing and therefore Coding Train, maybe the 4th version will be slightly faster. I love the syntax though, wish Processing just compiled to C or something... So much gratefulness for all that you have done and are doing! Thank you! 🤍