Jump to content
Posted 21 February 2013 - 02:39 PM
Posted 21 February 2013 - 04:04 PM
Edited by frob, 21 February 2013 - 04:04 PM.
Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.
Also check out my personal website at bryanwagstaff.com, where I occasionally write about assorted stuff.
Posted 21 February 2013 - 04:12 PM
I think you would be better served with a loose quadtree, which allows for a bigger range of motion because each quadtree node has motion on it.
As for your tree being "20-30+ nodes deep", you must either have an amazingly big world or a extremely tiny subdivision space.
At 1 meter per cell, a 20 deep quadtree will cover an area of just over one million meters by one million meters. Roughly the entire land mass of New York City at a one-meter-per-cell ratio.
A 30 deep quadtree will cover over the entire state of California, or the entire state of Texas, at one millimeter per cell accuracy.
For our complete 10km square world we have a depth 10 loose quadtree at 1 cell per meter.
It came out right in my head.... I meant it could be checking that many nodes each time, (5 - 7 nodes deep multiplied by the 4 nodes each might possibly check). I'm using the quad tree for several objects in my game, all but one are very static so I don't have to worry about those.
One container stores all the aI-creatures though, and I use a system similar to diablo where only awake creatures are ever updated, and any creatures outside a certain range from the player are automatically considered a sleep. So in theory I will only ever move creatures in close range to the player. But these objects can move from one side of the world to the other instantly but that shouldn't happen often.
The other big question I forgot to ask, is an easy way to find all the nodes that border a node?
Edited by freeworld, 21 February 2013 - 04:13 PM.
Posted 22 February 2013 - 05:16 AM
I'm using the quad tree for several objects in my game, all but one are very static so I don't have to worry about those.
If you need to detect collisions between any two of these objects, then this may be a good choice. However, otherwise consider using more than one quad tree. If there is only one of the objects that isn't static, then it may be an advantage to have a quad tree of its own for this object type.
...Such as no need to reinsert if it still is in the current node.
Are you sure you need this? It is a performance optimization, but do you have measurements that show this is needed?
Using more than one quadtree is a simple solution that can also improve performance.