Author Topic: Finding nearest brick - Is there a more efficient way?  (Read 351 times)

I am looking for a way to find the nearest brick to a given position from the client side.  This function works, but it lags in busier servers.
The find next radius search does not work on the client side.

Code: [Select]
function getnearestbrick(%pos)
{
for(%a=0; %a<serverconnection.getcount(); %a++)
{
if((%b=serverconnection.getobject(%a)).getclassname() $= "fxDTSBrick" && %b.isplanted())
{
%bpos = %b.getposition();
%dist = msqrt(mpow(getword(%bpos, 0) - getword(%pos, 0), 2) + mpow(getword(%bpos, 1) - getword(%pos, 1), 2) + mpow(getword(%bpos, 2) - getword(%pos, 2), 2));

if(%dist < %bestdist || %bestdist $= "")
{
%bestdist = %dist;
%bestid = %b;
}
}
}
return %bestid;
}

Is there a more efficient way of doing this?

Using the accelerated vector libraries would help.
Code: [Select]
%dist = vectorDist(%pos,%bpos);

Everytime the serverConnection count changes, make a new fxDtsBrick cached list rather than having to loop through every server object. Not much else you can do.