Jump to content
froggyluv

First AI to Detect Enemy [Question]

Recommended Posts

So need to determine which AI in group detects the enemy so he can specifically call it out (seperate from the default game callouts) but am finding that all units in a group are aware of the enemy at the EXACT same time

 

_teamK =[];   ////The Team that Knowsabout Enemy - generally the Player's team

{ _name = name _x;

  _ne = _x findnearestenemy _x;

  _nameE = name _ne;

  if (_x knowsabout _ne >.8) then {

  _teamK pushback _x;

  sleep .1;                                   /////////////Was hoping to create artificial delay here so 1st soldier to spot would be listed first -futile..

  _caller = _teamk select 0;

  hint format ["%1: Theres %2!", _caller,_nameE]}} foreach units group player;

 

player sidechat str _teamK;

 

 

This builds and shows array of the group that has spotted enemy but it lists them all simultaneoulsy - I cant believe there is no delay in terms of which specific soldier has spotted an enemy and the rest of that units team -not even a millisecond BI?? So when using _caller = _teamK select 0, it always selects the Player for instance as he is first in that array.

 

 

Share this post


Link to post
Share on other sites

Doubt it's doable to detect a single entity who spotted the enemy first since it's basically instant, at least with the granularity to check stuff like that (once per frame, no idea if it can get any faster?):


GOM_debug_reports = [];
GOM_testEH = -1;
GOM_testEH = addMissionEventHandler ["EachFrame",{

	{
		_targets = _x targets [true];

		if !(_targets isEqualTo []) then {

			GOM_debug_reports pushBack format ["%1 spotted %2 at %3",_x,_targets select 0,diag_tickTime];
			removeMissionEventHandler ["EachFrame",GOM_testEH];
			copyToClipboard str GOM_debug_reports;
			systemchat str GOM_debug_reports
		};
	} forEach units testgroup;
}];

//returns
["B Alpha 1-1:1 spotted O Alpha 1-1:3 at 643.706","B Alpha 1-1:2 spotted O Alpha 1-1:3 at 643.706","B Alpha 1-1:3 spotted O Alpha 1-1:3 at 643.706","B Alpha 1-1:4 spotted O Alpha 1-1:3 at 643.706"]

The culprit is that enemies are instantly shared among all units in a group.

Seems the enemy info is either shared faster than a frame takes (16.67ms at 60fps), or it's handled engine internally in an instant, no clue.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
8 hours ago, pierremgi said:

Then, you need some discriminants : You can try to pick up who have a sight of the enemy, who is nearest...

Like Pierre said, plus add a check who is facing towards the target +/- a few degrees.   Here's an untested loop for that.  This loop should give you the list of guys who can see the target.  Add in some code to narrow it to closest dude and you're done.

_firstSpotterCandidates = [];
{
    _angleDiff = abs(getdir _x - ([_x, _targetDude] call BIS_fnc_dirTo)); 
    if (_angleDiff <= 20  and [objNull, "VIEW"] checkVisibility [eyePos _x, eyePos _targetDude]) then
    {
        _firstSpotterCandidates pushback _x;
    };
} foreach units _spottingGroup;

This is way more fun than the work coding I should be doing right now.  I really need to unplug from this site during work...!!!

  • Like 1
  • Thanks 1
  • Haha 1

Share this post


Link to post
Share on other sites
2 hours ago, johnnyboy said:

 

  I really need to unplug from this site during work...!!!

 

Your boss.. if you're not,... should play Arma 3.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, johnnyboy said:

Like Pierre said, plus add a check who is facing towards the target +/- a few degrees.   Here's an untested loop for that.  This loop should give you the list of guys who can see the target.  Add in some code to narrow it to closest dude and you're done.


_firstSpotterCandidates = [];
{
    _angleDiff = abs(getdir _x - ([_x, _targetDude] call BIS_fnc_dirTo)); 
    if (_angleDiff <= 20  and [objNull, "VIEW"] checkVisibility [eyePos _x, eyePos _targetDude]) then
    {
        _firstSpotterCandidates pushback _x;
    };
} foreach units _spottingGroup;

This is way more fun than the work coding I should be doing right now.  I really need to unplug from this site during work...!!!

 

Yes thanks man - for some reason ive always resisted learning or using commands like abs/lineintersects/checkvisibility forever -funny cause it seems i always need them...old man stubborness i guess. Your loop does the trick just needed to add an integer check to checkVisibility

checkVisibility [eyePos _x, eyePos _targetDude] > 0) - im guessing greater than zero implies some visibility?

 

Just show your boss those chickens -if he cant apprciate them at high velocity than HE"S got issues!

 

@GOM: Yeah how hard would it be for BI to place miniscule delays to the rest of group as this would also help humanize their immediate response times abit

 

 

  • Like 2

Share this post


Link to post
Share on other sites

Frogman, how about posting your final script?  This seems like a script myself and others will want to use.  Did you distance screen to get closest spotter?

Share this post


Link to post
Share on other sites

Ok -lemme test it it out  a bit more -wanna run it thru a bunch of situations first

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

×