Ok, so I thought that next on my list was tackling some AI. I was looking at Boids Psuedocode for a flocking setup (http://www.vergenet.net/\~conrad/boids/pseudocode.html)).
Well, I set up a new project, got a background and some sprites. Im populating the list, and displaying the sprites, then with a short delay it starts updating. Problem is, only some of the entities are behaving properly, the rest dart to the bottom right hand corner. I added in a virtual 'goal' for them to attempt to get to, and as you can see in the video, a couple do, the rest do not. They're all operating off the same rules, so where am I going wrong here?
Its Rule 2 that Im having the problem in I think, since as soon as I make it return a 0,0 vector they all flock to the point they are supposed to, they just dont keep a distance from each other like rule 2 is supposed to provide. Any insights?
game1.cs - http://xna.pastebin.com/m48636854
flutterby.cs - http://xna.pastebin.com/m34f94e13
Project source if you have xna 2.0 installed - Zipped - 597kb
Video of errant behavior: http://www.youtube.com/watch?v=QJhuRkMasxc
Anyone see where im going wrong? I think i've gone cross eyed..
With a quick glance it looks like you intended to divide the rule 2 result vector by count, but did not do so. Since this is done for rules 1 and 3 it could result in a huge bias towards rule 2.
First thing you should use Vector2.Distance as simply subtracting x and y does not return the correct value.
Also I think you have to take into account that the second flutte could be on the right/left or above/below I would guess that the calc should differ, ie subtracting is ok when the other is on the right side, but will bring them closer if on the left side.