Here is my ugly and partly not working obstacle avoidance try. A little bit background for the applet: The creatures are normally wandering and flocking, also checking obstacles, when an obstacle is at a distance that is dangerous for the creature, the creature quits flocking and wandering and makes the avoidance. Craig Reynolds has a great paper dated 1999 that he explains what’s going on in details: Steering Behaviors For Autonomous Characters
there are certain problems with this approach. First of all, since the boids are moving together, some of them quits flocking but the ones in the behind do not since they are yet not at the dangerous point for the obstacle, and so that they pass through the obstacle. also as Reynolds explained in his paper, when you subtract your boid’s force from the obstacle’s force if they are head to head to each other, the boid stops instead of steering. One workaround could be checking the force from multiple points.
I must admit my obstacle avoidance algorithm is too simple and it should be improved more. While searching for boids I have come across to Michael Chang’s very nice application while he did in Reas’ Design for Interactive Media class. Actually he did a very good job writing this algorithm for the avoidance especially for the bounding box which avoids obstacles. I studied his code and it looks like he is using polar coordinates instead of what I am used to, cartesian coordinates. I must say the polar coordinates somewhat come handy and make much more sense and easier to understand at some points. To refresh our memories what is the difference between polar and cartesian coordinates, we can check out this link.