CodingTrain / Suggestion-Box

A repo to track ideas for topics
571 stars 86 forks source link

Unrealistic turns in boids simulations #1623

Open patwork opened 3 years ago

patwork commented 3 years ago

Hi, I have a question about boids simulation. Is there a way to improve core algorithm to prevent unrealistic, almost instant turns when new target is behind boid? Maybe some limit to rotation, but how to implement this in seek behavior without ruining other parts of simulation?

I've created simple example with sprite: https://editor.p5js.org/patwork/present/Z82AjNDss

manno-xx commented 3 years ago

Accidentally I was tinkering with this somewhat. Not the prettiest code, but https://editor.p5js.org/manno/sketches/PPzf3nQmf makes sure that the angle between velocity and desired vectors cannot exceed a max set angle. Makes it at least go around with a curve and not turn on the spot. Haven't tried to incorporate it yet with other steering behaviors, but I cannot see why it shouldn't work if you properly incorporate it in a seek function.