The nearestObjects commands supports array of types, which makes it more preferable to nearObjects.
I'd like to suggest two more improvements to make it a much more complete command:
- There are times that one wouldn't want sorting. Would it be possible to add a new parameter to disable sorting? (similar to nearestTerrainObjects):
nearestObjects [position, types, radius, 2Dmode, sort = true]
- All of the near(est)(Terrain)Objects commands simply measure the distance to the object center, which means the search radius would have to be at least as large as the object bounding radius to find the object. So you have no choice but to deliberately choose a large radius to find objects. (a value of ~70 meters can ensure that the largest object in the game can be found too)
Unfortunately using a large radius can be slow and wasteful. Would it be possible to add a new parameter that uses "combined radius" to find objects?
In other words, the new criterion for returning objects becomes:
_obj distance _pos < _radius + _obj.BoundingRadius;
This allows detecting objects even with a search radius of 0! Which can be useful for detecting if the position is inside the bounding box of another object, without wastefully using a large radius.
Of course, any other criterion that achieves the same result is welcome too; the point is detecting if a position (or sphere, if searchRadius > 0) is inside the bounding box of other objects.
Another sample application would be using this command to create a "selective findEmptyPosition" algorithm.
So the new syntax becomes:
nearestObjects [position, types, radius, 2Dmode, sort = true, useCombinedRadius = false]; // if useCombinedRadius = true, uses "combined radius" equation as mentioned above
optionally, this new parameter can be added to other near(est)(Terrain)Objects commands.