Action / RTS quad tree algorithm needed
I have a need for a bunch of units that move around to quickly find all the other units within N distance of itself. This is a 2D space game and the units may 'stack'. These units will also frequently move around.
I have been told what I need is a quad tree which is very good at space searches, but mostly they are poor handling objects that move around within them. I was also told that there are some implementations of quad trees that do a decent job of handling objects that move around. Is there any example of this someone can point me to?
Meh. I would use a simple "bin" approach. Divide your map into square sections (the bins) slightly larger than the distance you want to check. When you update a unit's position, set it up in the correct bin using the integer quotient of its x and y position.
Then when you want to find all units within N distance of a given unit, you only need to search its bin and the 8 bins around it.
Cache the distances you calculate if there is a good chance the other units will perform the same check on you.
Then when you want to find all units within N distance of a given unit, you only need to search its bin and the 8 bins around it.
Cache the distances you calculate if there is a good chance the other units will perform the same check on you.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement