Blockland Forums > Modification Help
Finding nearest brick - Is there a more efficient way?
(1/1)
Nexus:
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: ---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;
}
--- End code ---

Is there a more efficient way of doing this?
Destiny/Zack0Wack0:
Using the accelerated vector libraries would help.

--- Code: ---%dist = vectorDist(%pos,%bpos);

--- End code ---

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.
Navigation
Message Index

Go to full version