Jump to content
Sign in to follow this  
Tand3rsson

I see you.. (Q about checking if AI sees player/unit)

Recommended Posts

Hello fellow forum users!

I found an old thread on this from 3 years ago without any answers, and also, that was not for ARMA 3, so my appologize if a new thread is wrong of me.

I am looking for a solution to check if an AI character can see another unit. I know about knowsAbout and such, however, the problem I have with knowsAbout it that it stays high even after the unit has moved out of the AIs line of sight. Is this possible?

What I am trying to achive is, simply explained:

Player (or other unit) is for example standing behind a tree, a rock or a building, out of the AIs line of sight. canSee == 0,

Player (or other unit) steps out of cover, into the AIs line of sight, canSee == 1,

Player (or other unit) steps back into cover, canSee == 0,

A thought I have is that, when the AI can use their weapon against a unit, they obviously see him... is there a way to check that intent with an AI soldier?

All help is appreciated! I really do wish for a canSee command for BIS though ;)

Share this post


Link to post
Share on other sites

Thank you! I shall play around a bit with this and see if I might get it to work :P Always nice to see a new command that you weren't aware of :D!

EDIT:

ok, I can't get it to work. If I understand the wikiexampel correctly:

lineIntersects [eyePos player, aimPos chopper, player, chopper]

Would check if the something is between the player and chopper, is that correct?

And, if I am correct so far, then you would check if true like below:

 _doTheyIntersect == lineIntersects [eyePos player, aimPos chopper, player, chopper]

and then for exampel a

while "_doTheyIntersect == true" do {hint "YES"; sleep 25;};

I saw there was a feedback on lineintersects being broken , so I have to ask to know if this would be the correct way of doing it?

EDIT2:

_unitOne = _this select 0;
_unitTwo = _this select 1;

while {true} do {
_pos1 = eyePos _unitOne; 
_pos2 = getPosASL _unitTwo; 

if (lineIntersects [_pos1, _pos2, _unitOne])  then {hint "I don't see you";} else {hint "I see you";};  
sleep 10;
};

Solved, however, this results in _unitOne having Eyes in the back of his head!

Edited by Tand3rsson
I was dumb

Share this post


Link to post
Share on other sites

You would have to add some sort of directional check to it as well. Also a range might be a good idea.

Something in the line of this (didn't test it, you might wanna check the _shouldBeFacing part.):

_unit = _this;
_target = ??

_unitFov = 120;

_unitDir = dir _unit;
_tagetPos = position _target;
_unitPos = position _unit;

_shouldBeFacingDir = ((((_unitPos select 0) - (_unitPos select 0)) atan2 ((_unitPos select 1) - (_unitPos select 1))) + 360) % 360;

_canSee = false;
if(_shouldBeFacingDir - (_unitFov  / 2) >=  _unitDir && _shouldBeFacingDir + (_unitFov / 2) _unitDir) then
{
     if(_unit distance _target < 500) then
     {
           if (lineIntersects [_pos1, _pos2, _unitOne]) then
           {
                    _canSee = true;
           };
     }
};

Something in the lines of this should get your result. I also did the shouldBefacing and distance part first because it's less CPU intensive then the lineIntersects.

Share this post


Link to post
Share on other sites

_shouldBeFacingDir = ((((_unitPos select 0) - (_unitPos select 0)) atan2 ((_unitPos select 1) - (_unitPos select 1))) + 360) % 360;

Erm so 0 then :) I presume that was meant to be

_shouldBeFacingDir = ((((_unitPos select 0) - (_targetPos select 0)) atan2 ((_unitPos select 1) - (_targetPos select 1))) + 360) % 360;

Or just use BIS_fnc_inAngleSector instead.

//[<center position>,<center angle of sector>,<sector width>,<position>] call bis_fnc_inAngleSector;
if ( [_unitPos, eyeDirection _unit, _unitFOV, _targetPos] call bis_fnc_inAngleSector ) then {

_____________________

if (lineIntersects [[color="#FF0000"]_unitpos, _targetpos[/color], _unitOne]) then
{
       _canSee = true;
};

Not sure if its changed in the last few patches but intersects does not (did not) pick up unit models. As in Tand3rsson EDIT 2 above. ! intersects = cansee

Share this post


Link to post
Share on other sites

Hi

TPW has an excellent script called TPW AI LOS, which does exactly the same thing, just check his script. You can easily add WHAT should happen if an AI sees any of the players. I do not know however how well it works in ArmA 3 as I have only used ArmA 2 so far.

Share this post


Link to post
Share on other sites

Yeah, definitely don't rely on KnowsAbout. It's just a representation that the AI thinks you're somewhere around a certain area and that he's concerned about you. You could be sprinting away while he thinks you're standing still, and the value is still 4.

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
Sign in to follow this  

×