In a tower defense game for example, I want to get all the entities within a splash tower's range. How is this usually implemented?
Quickly retrieving entities by position
Moderators - Reputation: 31257
Posted 31 May 2013 - 09:45 PM
Most major 3D games use a spatial tree, such as a loose quadtree, and store object IDs in there. When an object is moved the corresponding entry gets updated. Queries for overlappinng areas of a spatial tree are extremely quick and will return a collection of object IDs.
If your game is tiny and you only have a few dozen or even a few hundred objects and the checks are rare, a simple brute force check to get the squared distances may be more than adaquate.
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.