Page 1 of 1

Algorithm for finding nearest entity

Posted: Thu Apr 28, 2016 12:51 pm
by Simcra
Hi all,

I have been struggling to achieve an efficient algorithm for finding the nearest entity of a certain type to an entity or player in the same surface. I am aware that a function already exists for finding the nearest enemy to a player in the game and that it is quite optimized, I need something equivalent to this. Does anyone have a working algorithm that fits this criteria or could perhaps point me in the right direction? Again, my appologies if this is in the wrong forum.

Kind Regards,
Simcra

Re: Algorithm for finding nearest entity

Posted: Thu Apr 28, 2016 1:25 pm
by Rseding91
The internal data structures for entities aren't setup for a "find nearest of type" - you'd just have to find all and iterate checking distance - which is inefficient at best and horribly slow at worse due to all the extra memory allocations of finding entities and pushing references into the lua state.

Re: Algorithm for finding nearest entity

Posted: Thu Apr 28, 2016 2:33 pm
by Simcra
That's sad, I'm guessing it's not worth feature requesting this?