Jump to content
thetrooper

enemy unit doWatch closest bluefor unit

Recommended Posts

Hi all. I'm trying to set a enemy unit to look in the direction of the closest bluefor unit.

If a different unit appraches closer to him he will then look in that direction. Any ideas?

Share this post


Link to post
Share on other sites
params["_unit"];

private _target = objNull;
while{alive _unit} do {
    private _nearest = _unit findNearestEnemy _unit;
    if((!isNull _nearest && (_nearest distance _unit < _target distance _unit)) || (isNull _target && !isNull _nearest)) then {
        _target = _nearest;
        _unit lookAt _target;
    };
    sleep 1;
};

Untested and without warranty ;)

 

Maybe you need an additional check for _target being null at the beginning if something distance objNull produces an error.

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

×