Jump to content
Kolmain

Select Nearest object from array

Recommended Posts

Im randomly selecting a point known as _pos, then I need to check which object _pos is closest to, us_trig, ru_trig, cdf_trig, or ins_trig. For each object it is closest to, theres a differnt _fac. so if the closest object to _pos is us_trig then _fac = "USMC" and so on, if then statments tend to not work so well, maybe theres a different syntax, any ideas?

Share this post


Link to post
Share on other sites

Something like this?

_closest = objNull;
_closestdist = 100000;
{
 if (_x distance _pos < _closestdist) then {
   _closest = _x;
   _closestdist = _x distance _pos;
 };
} forEach [us_trig,ru_trig,cdf_trig,ins_trig];

_fac = switch _closest do {
 case us_trig: {"USMC"};
 case ru_trig: {"RU"};
 case cdf_trig: {"CDF"};
 case ins_trig: {"INS"};
};

Share this post


Link to post
Share on other sites

@Shuko

That looks great, ill try it!

@PvPscene

I know of the nearestObjects, but im not looking for a type, im looking for pre-placed units in an array :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×