Sign in to follow this  
Kirl

group/flock tracking - Flash

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this