You are wasting time computing the actual distance. Instead of `getDist()`, create a `getDistSquared()` function, and compare against the square of the vision distance. creatureViewDistSquared = creatureViewDist * creatureViewDist ... if getDistSquared(creature.pos, otherC.pos) < creatureViewDistSquared: ... But first, do the partitioning as suggested by maxb.