Home   Help Search Login Register  

Author Topic: Finding out smallest distance between several objects.  (Read 1198 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Hello,

Does anyone have an idea how to do this:

Let's say I have a squad of 20 guys and I want an enemy "huntingteam" to follow the unit in the squad that is closest to the leader of the "huntingteam".
How can I do this in a smart way? Is there a way to find the smallest distance or number in an array or something like that?
min and max only seem to deal with 2 numbers, not more.

I know all the move commands, but not how to find the smallest number.

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline i0n0s

  • Former Staff
  • ****
Re: Finding out smallest distance between several objects.
« Reply #1 on: 26 Nov 2008, 01:08:24 »
Code: [Select]
_nearest = objNull;
_nearestDistance = 2000000000;
{
  _dis = _x distance (leader huntingteam);
  if (_dis < _nearestDistance) then {
    _nearestDistance = _dis;
    _nearest = _x;
} forEach units group

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: Finding out smallest distance between several objects.
« Reply #2 on: 26 Nov 2008, 21:18:48 »
Thanks alot, will try it asap.

Laggy
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.