If You Can Dodge a Wrench…

Obstacle avoidance is finally working.  Well, without any major issues leaping out at least.  Math, math and more math.  What appears to be extremely simple at first viewing ended up taking up a significant amount of time.  Minor math problems, code organizational problems, all compounded with the AI code messing it up as it goes created a problem that I spent far too much time tracking down.

Two week of struggles all down to not properly narrowing focus and trouble shooting each area piece by piece.  The amount of code that exists for this is stupidly small.  Unfortunately the AI has a mind of its own preventing me from reproducing collision issues consistently with it included in the equation.

AvoidInfo

The obstacle avoidance is based on some pretty simple vector calculations.  Although this may or may not be the best way to do it, the benefit of it is… it’s simple, and it will work with the existing flocking AI since it also uses vectors.   Anytime an AI creature enters the sphere of influence of an object I start the calculators.  I get the current white vector of the creature, the opposite blue vector from the object to the creature, and finally the red distance line to the object.  I then get the average green vector based of the blue and white and multiply it based on a curve from the red line.  The farther the creature is from the object, the less influence it has on its direction, the closer it is, the greater the change in direction.

This was probably the first time ever that a bell curve has been remotely useful.  Thanks to  Desmos, a handy little website that lets you enter equations and see the resulting graph it wasn’t too difficult.  Thanks to the bell curve  or Normal or Gaussian Distribution Function… ( I’m pretty sure you don’t care what it’s called), not only do I get the AI to increase its flee direction the closer they are, but I get the negative affect when they are farther away.  The obstacles will act as gravitational bodies pulling the creature towards it.  Although initially this was unintended it creates a more fluid avoidance as the creatures tend to more frequently hit the apex of  the object.

For those who don’t have $500 million to spend but don’t like the vector based object avoidance, I came across this nice little article in my travels.

Next up…. hopefully I’ll resolve some camera issues on the mobile version and get the rest of the AI working with the obstacles.