group/flock tracking - Flash

Started by
0 comments, last by Morrandir 15 years, 7 months ago
I have a dynamic nr of balls on screen (between 5-20) which clump together when close to eachother, I want to keep track of the individual groups that form and disband. I am already checking each ball against each other ball for collision detection, so I was thinking of creating an array inside each individual ball, which holds all balls that touch it. But I fear it might be quite cpu & memory intensive to populate all these arrays at every frame. I know it's not a great solution, so before starting work on it I was hoping for some clever alternatives.
Advertisement
There are multiple ways to go about this problem, and the best approach depends on what you want to track the groups for.

Whatever approach you choose however, repopulating the structures you use for storing connection data (whatever structure you end up using) is a cost you can avoid only if you can do incremental updates, and for that you have to be able to detect not only balls colliding, but also splitting up.

The structure for holding the connection data is an orthogonal issue. Two useful solutions off the top of my head:

1. Your method, which is basically a graph of connectivity on the balls, with all the pros and cons of graph structures

2. Making separate Group objects which are basically containers holding Ball references. Strongest point is easy iteration over the entire group

This topic is closed to new replies.

Advertisement