Saturday, July 12, 2008

All is Normal . . .

and that's the problem.

The Boids are jumping just a bit too much for my liking, but it's taken me till now to figure out why. There is a hint in the title, but first, the most recent flock of Boids. Move the mouse, they should follow. But they do have minds of their own.



Why are they jumping like manic goldfish when they see a food jar? Well, to make the Boids flock, we have to figure out how to move them and to where. So, I create a somewhat weighted list of vectors for each Boid, to figure out a direction to travel that keeps it near the most friends. Each other Boid that it wants to be near gets the vector normalized to a unit vector, just 1 pixel long according to Flash. When it gets too near another Boid, the vector gets longer the other direction, to keep them apart.

So, when the Boids get too clustered, those 'panic' vectors really outweigh any sane value keeping the flock together. Working in 3 dimensions will help, because the Z value will let them move in ways that just don't appear here, and I hope will disguise the jumpiness. First option is to always re-check my math to see what I can change safely, to better weight the various vectors, because 7 units towards the flock gets swamped by a large value like 20 away.

Numbers above represent actual values of the vector lengths. 1 unit vector towards the flock for each other Boid it wants to join, but when one is too close, the crash warning tells it to swim the opposite direction very quickly, and 20 seems to be the value that keeps showing up.

Last resort, is to give these Boids something to quell their panicy flights away from the flock. I've looked at tuning the numbers to keep them sitting still when they don't need to move far, or just slowing their movements down to make the jumping less erratic. As always, if math fails, try something unusual.

1 comment:

Dr Simone Paterson said...

boids on really strong coffee, totally jittery - just like i feel.
will talk to you today and tell you how i messed up our working sample in DAAS lab
see you soon
s