Jump to content
Sign in to follow this  
SaOk

Line Of Sight (Example Thread)

Recommended Posts



Newer vid (by McLupo) with eye direction demonstration:



Here is example of the new LOS commands that came with the recent beta. I have two units on map (AI named b, player a) and functions module placed on map. LOS is counted for eye positions and eye directions for AI . Use, edit & expand freely.

Requires Beta 94103 or newer.

LOS.sqf:
private ["_a","_b","_dirTo","_eyeD","_eyePb","_eyePa","_eyeDV"];
//Player
_a = _this select 0;
//AI to see or not
_b = _this select 1;
while {true} do {
_eyeDV = eyeDirection _b;
_eyeD = ((_eyeDV select 0) atan2 (_eyeDV select 1));
if (_eyeD < 0) then {_eyeD = 360 + _eyeD};
_dirTo = [_b, _a] call BIS_fnc_dirTo;
_eyePb = eyePos _b;
_eyePa = eyePos _a;
if ((abs(_dirTo - _eyeD) >= 90 && (abs(_dirTo - _eyeD) <= 270)) || (lineIntersects [_eyePb, _eyePa]) ||(terrainIntersectASL [_eyePb, _eyePa])) then {
hintsilent "NOT IN SIGHT";
} else {
hintsilent "IN SIGHT";
};
sleep 0.1;
};



LOSforSingleCheck.sqf:

private ["_a","_b","_dirTo","_eyeD","_eyePb","_eyePa","_eyeDV"];
//Player
_a = _this select 0;
//AI to see or not
_b = _this select 1;
_eyeDV = eyeDirection _b;
_eyeD = ((_eyeDV select 0) atan2 (_eyeDV select 1));
if (_eyeD < 0) then {_eyeD = 360 + _eyeD};
_dirTo = [_b, _a] call BIS_fnc_dirTo;
_eyePb = eyePos _b;
_eyePa = eyePos _a;
if ((abs(_dirTo - _eyeD) >= 90 && (abs(_dirTo - _eyeD) <= 270)) || (lineIntersects [_eyePb, _eyePa]) ||(terrainIntersectASL [_eyePb, _eyePa])) then {
hintsilent "NOT IN SIGHT";
} else {
hintsilent "IN SIGHT";
};



https://www.dropbox.com/s/5644ns4x9o9w710/LineOfSight.Desert_E.7z

Edited by SaOk

Share this post


Link to post
Share on other sites

Excellent work! Looks like it will be usefull for AI behavioural FSM's?

Share this post


Link to post
Share on other sites

Makes me want to make a Metal Gear Solid style "Huh, what was that noise?" sound that's played whenever you enter LOS

Share this post


Link to post
Share on other sites

Very interesting. Must to try this, wneh official, stable patch with this commands will be released. Just looking for most efficient way for doing similar things, and want to compare this with some sqf solutions. One of the most exciting scripting topic for me, but rather for some kind of overall, wide sector FOV checks, than for strictly, precise LOS test between two guys/objects/positions.

Share this post


Link to post
Share on other sites

I can see this potentially solving quite a few issues. The main one I can think of is AI shooting heavy machineguns while standing or kneeling that should only be shot while prone. A script could be setup to force the AI to go prone when it detects an enemy within a certain range while also maintaining line of sight. If it loses line of sight it goes back out of prone and back to its normal behaviour.

Share this post


Link to post
Share on other sites

I released new version 1.9 for my Zub mission featuring these LOS/Body Direction commands. You can find it here if interested:

http://forums.bistudio.com/showthread.php?132726-SP-MP-Dynamic-Whole-Map-Missions-by-SaOk

In the mission, bodies need to be now seen to be spotted. Civilians react on dead bodies for player if he is getting too close (if seeing those). Also checks are made, that certain things are not seen - friendly side and captives are not acting like blind now or all seeing in certain events.

Share this post


Link to post
Share on other sites

I think the biggest problem this could solve would be forcing AI to stop and shoot at units he has line of sight to that are under 50m away. If the scripts works instantly or close to it, the AI could actually be aware and competent in urban CQB.

Share this post


Link to post
Share on other sites

For the AI functions in Zub mission, I am looping nearEntities check in about every 3. second ((getposATL _z) nearEntities [["Ins_Soldier_Base","RU_Soldier_Base","CDF_Soldier_Base","GUE_Soldier_Base"],120]). You could loop it for 50m, when check the LOS´s. Already much less units to count that then. E.g. you could check the nearentities for group leader, then what enemies he see and then stop group.

Edit: Or try nearTargets.

Share this post


Link to post
Share on other sites

SaOK, that's a really excellent implementation of the new lineintersects function.

I tried your formula in a very small script which just makes AI units in the player's group kneel/crouch if they have line of sight of an enemy less than 150m away. Seems to work pretty well and doesn't cripple the computer.

Uncommenting this line: //0 = _unit fireAtTarget [_enemy]; , and decreasing the sleep =10 to sleep=1 or less, might also help in CQB as per maturin's suggestion

//UNITS IN PLAYER"S GROUP WILL AUTOMATICALLY KNEEL/CROUCH IF THEY HAVE LINE OF SIGHT OF NEAR ENEMIES
// Original idea by SaOK

//Enemies within 150m of unit
_nearenemies = 
{
_unit = _this select 0;
_nearunits = nearestobjects [_unit,["man"],150];
{
if (side _x == east) then {[_unit, _x] call _los};
} foreach _nearunits;
};

//Does unit have line of sight with enemy?
_los = 
{
_unit = _this select 0;
_enemy = _this select 1;
if (((abs(([_unit, _enemy] call BIS_fnc_dirTo) - direction _unit)) <= 90 || (abs(([_unit, _enemy] call BIS_fnc_dirTo) - direction _unit)) >= 270) && !(lineIntersects [[getposASL _enemy select 0, getposASL _enemy select 1,(getposASL _enemy select 2)+((_enemy selectionPosition "pilot") select 2)],[getposASL _unit select 0, getposASL _unit select 1,(getposASL _unit select 2)+((_unit selectionPosition "pilot") select 2)]])) then 
{
_unit setunitpos "MIDDLE";
//0 = _unit fireAtTarget [_enemy];
};
};

//Main loop
while {true} do 
{
{
_x setunitpos "UP";
[_x] call _nearenemies;
} foreach units group player;
sleep 10;
};

Share this post


Link to post
Share on other sites
I think the biggest problem this could solve would be forcing AI to stop and shoot at units he has line of sight to that are under 50m away. If the scripts works instantly or close to it, the AI could actually be aware and competent in urban CQB.

Would be even better, if it'd check how much of one's body is in LOS. If you stick the tip of your head up behind a window the AI shouldn't magically shoot you in the head, when it isn't aware of you.

Share this post


Link to post
Share on other sites

@Saok & tpw:

Splendid developments, thanks for sharing.

Hee, these new commands look like making a number of neat developments possible; particularly amusing as a couple of posters immediately labelled them "useless" in the beta thread.

Share this post


Link to post
Share on other sites

Not the best video quality, but lineIntersects is not limited to AI stuff :p

(I have another video but I'm too lazy to upload it)

Please watch fullscreen and in HD

cO_W7Vrr0_k

Edit: lineIntersects is called 30 times per frame in this example.

Xeno

Edited by Xeno

Share this post


Link to post
Share on other sites

Ummm what has this got to do with the lineIntersects?

The full patch will be out when it is ready TM

Share this post


Link to post
Share on other sites
Ummm what has this got to do with the lineIntersects?

The full patch will be out when it is ready TM

just asked because the commands only work with the beta for now. sorry for pushing this in here :o

Share this post


Link to post
Share on other sites

I updated the first post with example mission and updated the code to follow new eyePos command that is less heavy than the earlier method to get head´s position. Also added terrain check but it dosent seem to work for at least desert map. But the example works normally with objects/vegetarion/houses.

Share this post


Link to post
Share on other sites

You should really list both a and b as ignored in your tests (and in your example). It does not matter for soldiers (soldier bodies are - surprise - never included in visibility computations), but it would make a difference once vehicles are used as a or b.

Share this post


Link to post
Share on other sites

I havent tested yet but instead of the

direction b

It might be possible to get eye´s watching direction (instead of body direction), replacing that code with:

([eyePos b, aimPos b] call BIS_fnc_dirTo)

---------- Post added at 18:14 ---------- Previous post was at 18:08 ----------

You should really list both a and b as ignored in your tests (and in your example). It does not matter for soldiers (soldier bodies are - surprise - never included in visibility computations), but it would make a difference once vehicles are used as a or b.

What I then add as object list that the command dosent ingore? Is the heavy nearestObjects only way or is there another way (that is used as default with the command, if only two parameters are inserted)?

Also I cant get the terrainIntersect working or I am missing something. In the desert map it always gives out false, even when there is hill between.

(terrainIntersect [eyePos b, eyePos a])

Share this post


Link to post
Share on other sites

Also I cant get the terrainIntersect working or I am missing something. In the desert map it always gives out false, even when there is hill between.

(terrainIntersect [eyePos b, eyePos a])

Be sure to check the z value of the positions. I also had troubles first until I realized that at least one z value was a negative one or simply not high enough above 0.

Xeno

Share this post


Link to post
Share on other sites
Not the best video quality, but lineIntersects is not limited to AI stuff :p

(I have another video but I'm too lazy to upload it)

Please watch fullscreen and in HD

Edit: lineIntersects is called 30 times per frame in this example.

Xeno

Nice!

Share this post


Link to post
Share on other sites
Nice!

With the new available eyePos command in 93616 the result is great now. The names of the units vanish immediately now when you as a player lose eye contact (before it was just a position check of the unit and a stance check for the player so the drawing of the names or hiding them was always delayed a little bit).

Please note that all the 30 lineIntersects calls are really done every frame, the script is not running via execVM or spawn as otherwise the scripting engine itself could cause delays.

Xeno

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  

×