Find Nearest Object

Posted by ultifinitus on Game Development See other posts from Game Development or by ultifinitus
Published on 2011-07-01T15:09:11Z Indexed on 2012/11/08 17:27 UTC
Read the original article Hit count: 274

Filed under:
|
|

I have a fairly sizable game engine created, and I'm adding some needed features, such as this, how do I find the nearest object from a list of points?

In this case, I could simply use the Pythagorean theorem to find the distance, and check the results. I know I can't simply add x and y, because that's the distance to the object, if you only took right angle turns. However I'm wondering if there's something else I could do?

I also have a collision system, where essentially I turn objects into smaller objects on a smaller grid, kind of like a minimap, and only if objects exist in the same gridspace do I check for collisions, I could do the same thing, only make the gridspace larger to check for closeness. (rather than checking every. single. object) however that would take additional setup in my base class and clutter up the already cluttered object.

TL;DR Question:

Is there something efficient and accurate that I can use to detect which object is closest, based on a list of points and sizes?

© Game Development or respective owner

Related posts about c++

Related posts about 2d