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

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;};

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.

Logged

How can you shoot women and children?Easy! Ya' just don't lead'em so much! Ain't war hell?!!

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 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)

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?).