Sunday, 2 January 2011

Boid Brain Implementation

After spending two weeks working on LESS THAN THREE, then taking a few days off, I'm now back at work again continuing my efforts to code a new in-house boids system for the tube project in Python.  This will all be open sourced in due course once I've tidied up the code.

I spent a day or so bug-fixing and clearing out some redundant defs, then I implemented a 'flock metrics' system.  Rather than considering the entire collection of boids to be the flock (as the built in boids system does), in my boids system the flock is defined as all boids within a certain radius (the 'sight distance') making computations much faster (and more realistic for ground based creatures).  Each boid needs to know a set of statistics ('flock metrics') about the flock before it can make a decision on what to do (in the 'boid brain').  It needs to know how dense the flock is, how many boids are in the flock, where the centre of the flock is, who its closest neighbour is, and what the rate of change of all of these factors is.

For example if the flock is very dense but it is becoming less dense then the boid can stop panicking.  If the flock is not dense but it is increasing in density the boid may wish to align its direction vector with other boids in the flock so as not to cause collisions.  If the flock becomes severely dispersed a boid may wish to head for the centre of the flock for protection and so on.  This decision making is called 'emotion modulation'.  The boid considers the flock metrics and makes decisions about what to do automatically.  Emotions such as panic can change very quickly when a boid becomes blocked in by its neighbours (this is called ' high volatility' in the boid script) whereas emotions such as centring (heading for the flock centre) may need more gradual adjustments (low volatility) as boids slowly notice they have been left behind.



The next step is to allow the user to control emotions with 'emotion effectors' in the same way the boids can be physically directed with 'direction effectors' (shown in the above video).  The emotions implemented in the above video are panic, sleep, herd (copy neighbours directions/alignment), centre (head for the centre of the flock - traditional boid/shoal/flocking behaviour) and cluster (approach but keep a safe distance from closest neighbour).  The last emotion left to implement is not so much an emotion but a signal to other boids which is repel/attract (a boid can signal other boids to move closer or further away).

As you can see in the above video there is still a slight issue with collision stickiness which needs to be solved.

Fingers crossed I'll be able to start work on the autowalker pretty soon.

No comments:

Post a Comment