Home   Help Search Login Register  

Author Topic: How to check if the AI sees the player?  (Read 3600 times)

0 Members and 1 Guest are viewing this topic.

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
How to check if the AI sees the player?
« on: 23 Aug 2011, 14:21:52 »
Hello lads,

is it possible to know if the AI actually sees another unit (e.g. the player)? I'm not talking about knowsabout and the trigger option "detected by ...".

What I mean is that there is a moment where the AI switches to raise the gun if it sees an enemy. Knowsabout can be at max already but the AI still will do what it is told normally. Until it really sees an enemy. Then it will raise its gun and fire.
And I want to know if it is possible to know if this is happening.


I would use this information for something like this:

if ((AIenemyunit sees player) AND (playerIsArmed)) then {player setcaptive false;};


Do you have any idea?  :D
« Last Edit: 23 Aug 2011, 17:26:48 by Undeceived »
Current project: Black Lands (Arma 3)

Offline Ext3rmin4tor

  • Members
  • *
Re: How to check if the AI sees the player?
« Reply #1 on: 26 Aug 2011, 00:34:22 »
The AI reactions are all based on the knowsAbout level of the group. If knowsAbout is 0, then the unit has never been spotted by the AI, otherwise knowsAbout is greater than 0. This value is reset after the AI does not have new info on the spotted unit.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: How to check if the AI sees the player?
« Reply #2 on: 26 Aug 2011, 10:15:12 »
To my understanding the CBA addon (it's all text addon so it's like few hundred kbs "big") includes a function to see where a given soldier's head is pointing at.

Of course if you don't want to use the addon just for one function you might be able to make your own, I'm guessing they use model selection positions and the scripting commands related to those (like modelToWorld, selectionPosition..).
They also might have to use some other gimmicks because things are never that easy :P
The CBA function also returns the up/down direction of the head so you can check whether the soldier is looking on the ground or to the sky.

So with that if you're math savvy enough you should be able to cook up a function that first uses that CBA function (or your own) to check the head dir at given moment and then calculate a FOV "cone" using some pre-defined angle (whatever the basic human FOV is) to get the AI's FOV and then see whether the player is in it.

Can't help you more because I'm not math savvy at all, I can barely add and subtract (with a calculator)  :D
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: How to check if the AI sees the player?
« Reply #3 on: 01 Sep 2011, 20:06:20 »
:D Ok, that is a great suggestion, h-, but I fear that my math and scripting knowledge won't allow me this too. :D

Anyway, thanks for the answers.
Maybe someone gets an idea some day. :dunno:
Current project: Black Lands (Arma 3)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: How to check if the AI sees the player?
« Reply #4 on: 02 Sep 2011, 18:19:35 »
Hey, if you have time and will, you could tinker with nearTargets. _this select 5 and _this select 0 are both PERCEIVED positions/perceived accuracy of position. Now, in theory, if the perceived position == the actual (getpos) position of the object, then that would mean the unit actually 'sees' the other unit, whereas the moment the unit is concealed, the discrepancy between actual and perceived should get bigger, right?

I suggest you experiment a bit with this, it might prove fruitful! It depends, of course, on how quickly the perceived position starts getting lost after the unit disappears from sight, and also on other AI issues (such as: if unit B sees an enemy and reports him in, will unit A also have 100% true perceived position of the enemy, despite not actually seeing the enemy?).

Do it for ArmA Scripting Science! :good:

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Undeceived

  • Members
  • *
    • My missions and campaigns
Re: How to check if the AI sees the player?
« Reply #5 on: 15 Oct 2011, 13:27:31 »
Hello Wolfrug, thanks for your reply.

I have had another idea that may help me, but I'm not sure...

Is there a way to check if the AI is ready to fire? What happens (script / engine wise) in that moment, when the leader assigns a target to the AI and the AI aims at it and says "Ready to fire!"?

Does someone have a clue about this?
Current project: Black Lands (Arma 3)