Nearest Specific Entity


(Jason Pickering) #1

Is there a way to search for nearest entity, but entity not type? I want to find the closest enemy of a specific class. instead of jsut the nearest entity. I know there is a way to do this in code, by creating an array of those entities then sorting array by distance, but wondered if there was a fast way to do this.


(Ultima2876) #2

FlashPunk probably would do exactly as you describe internally anyway (array of entities then sort by distance), so if you don’t find anything there’s absolutely no problem in doing that straight off the bat(maybe start defining your own helper functions, or submit a pull request for it to be added into the main branch) :slight_smile:


(Abel Toy) #3

FlashPunk uses linked lists internally.

It’d be helpful to have those accessible outside internal FlashPunk code to be able to do stuff like this easily. I hate having to add functions to FlashPunk for my complicated search-entity functions.


(Ultima2876) #4

Ah yeah, I’m thinking of the World.getType-esque functions that put entities into an Array allowing you to further manipulate them.

However, access to the internal linked lists may break encapsulation. It’s kinda messy to be able to access that kind of internal stuff because beginners might do crazy stuff with it (such as breaking the linked list and then wondering why their entities are all disjointed and not updating etc).

Really, putting them into a vector isn’t that expensive :wink: