You should change your distance calculator, the way you are doing it is slower than it could be.
This
Is exactly the same as this
But it is considerably faster to use multiplication, here's the proof:
t# = timer()
for k = 0 to 100000000
v = v * 2
next k
t1# = timer()-t#
t# = timer()
for k = 0 to 100000000
v = v ^ 2
next k
t2# = timer()-t#
do
print("Multiply: " + str(t1#))
print("Squared : " + str(t2#))
sync()
loop
Another method you can use to speed up the distance check (A LOT) is to square the result so that you can avoid square rooting the check.
Your distance check would be this
distance = (ax-bx)*2 + (ay-by)*2 + (az-bz)*2
And then when checking if the distance is within a certain range you square the range, like this
if distance(...) < range*range then ...
AGK V2 user - Tier 1 (mostly)