#How to implement a vision cone? (Boids & Flocking)

4 messages · Page 1 of 1 (latest)

tough geode
#

I've been trying to figure out how to implement a vision cone for my boids. Is there a way to do it w/o implementing some type of ray casting? If not, then is there a way to check whether a line intersects with other shapes?

near quail
#

For your second question, yes - you can check out the library p5.collide2d (it's not too hard to implement it either, requires some geometry) (I am talking about regular shapes, for custom shapes things might be a bit tricky.)

tough geode
#

Thanks! I tried implementing a vision cone by calculating the angle between a boid and it's neighbors and it works but it's a bit slow. I'm checking into optimization like using quadtrees to make it have to do less comparisons.

I've heard of collide2d so I'll check that out too. Thanks!

little relic
#

you can use a cross product to check if a point is on one side of a line