So I’m using Unity to do this, but I’m not sure that matters.
I have enemies that are off the visible screen, and I’d like to have indicators on the side of the screen to denote where they are. That’s fine, but there’s a lot of enemies so I want to group them into blobs. As in, rather than showing 8 indicators on top of each other, I want 1 indicator with an (8) next to it.
So right now, my algorithm is:
- minimum blog range is a constant that I set
- loop through all enemies
- check distance to all enemies already assigned to blobs, if within range, assign to blob
- if not, check other non-assigned enemies, if any are within blob range, make a blob
I’m doing this every frame, and it feels inefficient. What can I do to improve this as well as save on processing between frames. As in, what could I do with the previous frame’s data to make this better (since the likelihood of the blob’s members changing is very low, but it’ll definitely have an updated position).
Or, should I just stop worrying about it and continue on, because it’s just vector math and it isn’t really going to cause problems for the engine.
You’re probably fine with whatever you have currently as far as processing power in concerned.
There is an interesting approach to the problem of proximity grouping using genetic algoritms: http://www.cbu.edu/engineering/maesc/maesc03/FullPapers/d3-1-doc.pdf
Also, this links here look promising: K-means algorithm variation with equal cluster size
But honestly, I’m good enough at math to actually give a solid answer…