Boids flocking behavior problem

Yesterday I stumbled upon Craig Reynolds Boids , and subsequently realized that I would suggest implementing a simple 2D version in Java. I put together a pretty basic setup based on Conrad Parker notes .

However, I get a rather strange (in my opinion) behavior. Currently, my combat vehicles move quite quickly into a coarse mesh or grill and continue to move in place. By this I mean that they move a little and rotate very often.

Currently I have implemented:

  • Alignment
  • Cohesion
  • Separation
  • Speed ​​Limit

At the beginning, my fights are randomly distributed over the screen area (slightly different from the Parker method), and their speeds are all directed to the center of the screen area (note that randomly initialized speeds give the same result). Changing the speed limit value only changes how quickly the coids move into this pattern, and not the pattern formation.

As I see it, it could be:

  • The consequence of the parameters that I use (now my code is described in the Parker pseudo-code, I have not tried the influence areas defined by the angle and radius, as described by Reynolds.)
  • Something I need to implement, but I do not know.
  • I am doing something wrong.

The expected behavior would be something more compared to the two-dimensional version of what is happening in the applet on the Boids Reynolds page, although now I have not implemented any way to save the boids on the screen.

Has anyone come across this before? Any ideas on the cause and / or solution? I can post the .gif of the behavior in question if that helps.

+7
source share
4 answers

Perhaps your weight for the separation rule is too strong, forcing all fights to move as far as possible from all neighboring collectors. There are different constants in my pseudocode that act as weights: / 100 in rule 1 and / 8 in rule 3 (and implicit * 1 in rule 2); they can be improved, which is often useful for modeling various forms of behavior, such as densely populated insects or gliding birds.

Also arbitrary | distance | <100 in the separation rule must be changed in accordance with the units of the simulation; this rule should only be applied to boids in close proximity, mainly to avoid collisions.

Good luck

+10
source

If they see everyone, they will all move at an average speed. If they see only a few, there may be separate groups.

And if they are randomly distributed, they will be close to zero.

If you limit them to a rectangle and either push them away from the walls, or teleport them to the other side when they get close) and have too high a separation, they will be pushed out of the walls (from the walls themselves or from others that have just been teleported, which then will be pushed to the other side (and press again and press again)).

So, try closer cohesion, limited vision, increase the space and distribute them in a cluster (select a random point and place several of them a small random distance from there), uneven or normal.

+2
source

I ran into this problem. I decided this, making sure that the method of updating each battle speed adds a new speed to the old, instead of resetting it. Essentially, what happens in this: battles try to move away from each other, but cannot accelerate (because their speeds are reset instead of increasing, as they should), thus, "twitching". Your speed update method should look like

def set_velocity(self, dxdy): self.velocity = (self.velocity[0] + dxdy[0], self.velocity[1] + dxdy[1]) 

where speed and dxdy are 2-tuples.

+1
source

I wonder if you have problems with collision rectangles. If you implemented something based on overlapping rectangles (like this ), you can end up describing the behavior when two rectangles are close enough for any movement to cause them to intersect. (Or even worse, if one rectangle can be completely inside another.)

One solution to this problem is to make sure that each boyd only looks forward. Then you avoid the situation where A cannot move because B is too close in front, but B cannot move because A is too close.

A quick check is to actually draw all of your collision rectangles and color any intersecting colors. It often provides the key to stopping and twitching.

0
source

All Articles