neokika 62 Posted June 8, 2012 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 This is something I've heard before (maybe from you :p). How to achieve that? I mean, it's not like there is some kind of non-scheduled thread that you can create with existent commands, is it? Share this post Link to post Share on other sites
xeno 234 Posted June 8, 2012 (edited) I mean, it's not like there is some kind of non-scheduled thread that you can create with existent commands, is it? Use the force, Luke :p (and no, I won't explain how it works you have to find out yourself, sorry, because it's probably not a method for everyone as you can easily halt the game or you can cause a massive FPS dropdown if used the wrong way) Edit: New video using eyePos (please watch in HD and fullscreen again) trkn5mtZ7F8 Xeno Edited June 8, 2012 by Xeno Share this post Link to post Share on other sites
kremator 1065 Posted June 8, 2012 Now that is very nice Xeno ! Have you any idea of the CPU load that this pulls ? What would happen with 100 units / 500 units etc ? Share this post Link to post Share on other sites
tpw 2315 Posted June 8, 2012 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 Care to expand on this a bit Xeno? I can't get terrainintersects to work either. I've never seen a negative z value when monitoring eyepos of player and target, but I have seen negative y values. Even if I change these all to positive (using abs), the terrainintersect stubbornly refuses to work. As per SaOk, it returns false no matter what. Share this post Link to post Share on other sites
xeno 234 Posted June 8, 2012 Have you any idea of the CPU load that this pulls ? What would happen with 100 units / 500 units etc ? At least on my system the lineIntersects did not cause any FPS drops. That doesn't mean it is the same with 100+ units. I always test under mission conditions, the test mission had about 100 AI units running around and lots of other scripts running. Xeno Share this post Link to post Share on other sites
SaOk 112 Posted June 11, 2012 (edited) I updated the first post with new sample mission. Now the eye direction is included. 93666 beta also made the terrainintersect work for eyePos. 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]) ||(terrainIntersect [_eyePb, _eyePa])) then { hintsilent "NOT IN SIGHT"; } else { hintsilent "IN SIGHT"; }; sleep 0.1; }; Thanks McLupo for the video: Edited June 11, 2012 by SaOk Share this post Link to post Share on other sites
McLupo 118 Posted June 11, 2012 (edited) Hi SaOk, you´re a freak ;) Im lost for words - today the Beta and you managed it so fast to offer a new "eye following" script... Wow...a dream comes true, i guess? My hat off mate!! A tribute for your impressive work! http://www.arma2base.de/include.php?path=forumsthread&threadid=1160&entries=0#post9390 Cheers McLupo Edited June 11, 2012 by McLupo Link added Share this post Link to post Share on other sites
SaOk 112 Posted June 11, 2012 Thank you, McLupo. :) Even at the end the script isnt that complex. I just created it piece by piece (using the available scripting commands & functions). Only half tricky part was the vision range (180) part and atan2. Had to remember some math, but at the end those wasnt that complex either, I just listed some possible combinations with min and max values and ended up with the code: abs(_dirTo - _eyeD) >= 90 && (abs(_dirTo - _eyeD) <= 270)) Not sure if there is more simple way (Xeno?) for that part, but I cant think more math for few days. :D At least the abs(_dirTo - _eyeD) is counted now twice. It could be added as own local variable. Share this post Link to post Share on other sites
zonekiller 174 Posted June 12, 2012 well done SaOk , clad to see theres no voodoo game crashing code in this :) thank you for sharing. Share this post Link to post Share on other sites
froggyluv 2135 Posted June 12, 2012 Man it just gives me so much joy to see this! :) Share this post Link to post Share on other sites
kremator 1065 Posted June 12, 2012 Really good to see members of the community willing to share their knowledge. Share this post Link to post Share on other sites
tpw 2315 Posted June 12, 2012 (edited) OK I've had a more serious attempt to use SaOk's magnificent code in a CQB situtation, without melting down the computer. This little script scans for enemies near each squad member, determines if the squaddie has line of sight to the enemy, and if so then forces him to kneel and shoot at the enemy. If the squaddie has no LOS to an enemy then he'll resume normal (auto) stance. I tried out a few identical CQB situations around Aliabad, with and without the script, and it certainly made my squad members much more responsive and aggressive. The below code is my first attempt at using cba_fnc_addPerFrameHandler (so you'll need CBA to run this) to lighten the load and really get the unit response time down to well under a second. It seems to work well but no doubt my implementation is tragically flawed and you can tell me all about it. Note: I've fiddled SaOk's code a little so that each squad member has to have the enemy within a 120 degree angle of view (not 180 degrees). This is partly for realism and partly because the eyedirection command has a few quirks - even though a unit can turn their head 90 degrees left or right, the eyedirection maxes out at about 60 degrees left or right. //UNITS IN PLAYER'S GROUP WILL AUTOMATICALLY KNEEL/CROUCH AND SHOOT IF THEY HAVE LINE OF SIGHT WITH NEAR ENEMIES // Needs beta 93666 or greater // Line of sight stuff adapted from SaOk // TPW 20120612 private ["_unit","_near","_nearunits","_cansee","_dist","_a","_b","_dirTo","_eyeD","_eyePb","_eyePa","_eyeDV","_ang","_tint","_lint"]; tpw_los = { { _unit = _x; _nextTime = _unit getVariable ["NextTime", -1]; if(_nextTime == -1) then {_unit setVariable ["NextTime", diag_tickTime + random 1];}; if(diag_tickTime >= _nextTime) then { _unit setunitpos "AUTO"; _unit setVariable ["NextTime", diag_tickTime + random 1]; _nearunits = (getposatl _unit) nearentities [["man","car"],200]; { _near = _x; _cansee = 0; if (side _near == east) then { //Line of sight stuff adapted from SaOk _a = _unit; _b = _near; _eyeDV = eyeDirection _a; _eyeD = ((_eyeDV select 0) atan2 (_eyeDV select 1)); _dirTo = ([_b, _a] call BIS_fnc_dirTo); _ang = abs (_dirTo - _eyeD); _eyePa = eyePos _a; _eyePb = eyePos _b; _tInt = terrainIntersect [_eyePa, _eyePb]; _lInt = lineIntersects [_eyePa, _eyePb]; if (((_ang > 120) || (_ang < 240)) && !(_lInt) && !(_tInt)) then {_cansee = 1;}; }; if !(_cansee == 0) exitwith { _unit setunitpos "MIDDLE"; _unit lookat _near; _unit dofire _near; //Debugging //_dist = round (_unit distance _near); hint format ["%1 -> %2 \n%3m",_unit,_near,_dist]; }; } foreach _nearunits; }; } foreach units group player; }; [tpw_los,0.5] call cba_fnc_addPerFrameHandler; Edited June 12, 2012 by tpw Share this post Link to post Share on other sites
SaOk 112 Posted June 12, 2012 There is definitely much to add, human can only see very close objects with the extreme angles. Depending also if the object is moving. Currently the function spots units in forests in notime. I should add a distance check, enviroment type (e.g. surface forest), is the seen object moving/in shadow, how tall it is, what color the object is (give hiding bonus for green uniform classes in forest), is the watchman moving, is he tired/paniced/suspisious, using binocular/scoper weapon... All would increase/decrease the time (min reaction time like 1sec) how fast the object is qualificated as seen, up to making the spotting very rare for certain conditions. For bigger distance it better to use the old knowsabout and behaviour check, then do some final LOS checking. Share this post Link to post Share on other sites
maturin 12 Posted June 12, 2012 I'd happily stress test the CQB on my low end computer if someone threw a PBO my way. /gimmegimmegimme Share this post Link to post Share on other sites
orcinus 121 Posted June 12, 2012 Wow! With the work Robalo is doing on stance for ASR_AI, AI combat functioning looks set to becoming greatly improved. Kudos to SaOK, tpw & the BIS devs for this. Share this post Link to post Share on other sites
tpw 2315 Posted June 13, 2012 I'd happily stress test the CQB on my low end computer if someone threw a PBO my way./gimmegimmegimme I will throw a PBO your way when I get home from work. Share this post Link to post Share on other sites
tpw 2315 Posted June 13, 2012 Maturin (and anyone else interested), here's a PBO version of the above script. http://www.gamefront.com/files/21839797/TPW_SAOK_LOS_100.zip I'd be interested to see how it performs for you. It runs OK on my shit computer, hopefully it will for you too. Share this post Link to post Share on other sites
CameronMcDonald 146 Posted June 13, 2012 /boner Awesome. Share this post Link to post Share on other sites
McLupo 118 Posted June 13, 2012 Hello to all,:) i´m "anyone", hehe... i got it. Thanks a lot for your effort, the PBO runs great, awesome!! Very helpful for noobs like me!!:bounce3: Cheers Share this post Link to post Share on other sites
kremator 1065 Posted June 13, 2012 I'm anyone too :) Just downloaded it! Testing ..... Share this post Link to post Share on other sites
maturin 12 Posted June 13, 2012 Thanks for PMing that PBO, TPW (acronyms galore). I think I may have found an important bug in the existing script, although I have no scientific tests to offer. I have a dual core 2.53 laptop, so I thought that if anyone can get this script to lag up ArmA, it would be me. I loaded the Ambush mission from my signature, with 100 AI in a single firefight. Yet before I could start in earnest, my own men went crazy and started gunning me down! This mission has the player's squad spread out in pre-set positions across a treeline. Your position spans several hundred meters, and I believe my men may have been seeing each other and somehow identifying their comrades as Unknown rather than Friendly. Then the LOS script told them to open fire on each other. This is my guess, anyways, and would point to a small oversight in the mock-up script rather than a big problem with the new LOS function. I hope my guess is correct, because then it means my mission isn't broken or there aren't deeper issues with LOS. Anyhow, my other CQB observations: AI reaction time is now kick-assingly fast. If I don't use human tricks to outflank them, it is a gunslinger's battle between equals. I can't state this too confidently, since the AI was always capable of near-instant kills, yet never did it consistently. But I ran without ACE and ASR and the AI did not suffer for it in CQB at all. The script as is does not really mitigate the AI's worst CQB problems, however: The AI acts stupidly in vanilla by running from cover to cover, even if the player is two meters away aiming a gun at them. This can result in AI running past or into the player at a defenseless sprint, and as I understand it, this is what the script was supposed to interrupt. While their fruitless dashes between cover may be getting interrupted by the script, it doesn't really happen fast enough, and I don't see them kneel to shoot very often. They will still spend their last seconds on earth running in plain view of the player, and won't stop to shoot if traversing a door in a wall or something. If the script is making them stop their run for cover, it isn't doing it fast enough, and it is actually easier to shoot someone who runs into the open and stops, rather than someone who sprints circles around you and keeps sprinting. The effect of this is that when you shelter inside a compound or courtyard, assaulting AI still expose themselves to your fire in the old way, rather stopping to shoot the moment they make contact. Forcing them to shoot when they have LOS doesn't fix the vanilla glitch of glacially slow aiming. They can still take multiple seconds to drag their gun barrels twenty degrees to the right. And I tested a firefight with four full squads of enemies (4 USMC Rifle and 4 RU Infantry), with no noticeable change in performance. I have an FPS reporter, so let me know if you want anything more quantitative in a specific situation. Share this post Link to post Share on other sites
tpw 2315 Posted June 13, 2012 Thanks so much for the in depth feedback maturin. I'm not sure where to begin addressing what you saw, so I will offer these observations and comments in return. 1 - the script is not altering AI FSM in any way (ooh, more acronyms), so if you have fundamental problems with their behaviour then at this stage you're going to be disappointed. 2 - the script only affects those AI in the player's squad, and only if you are blufor. If you played as opfor, then your squad will definitely have blown each other away. 3 - i tried it under a few cqb situtations (with and without ASR AI) and the general rule was as soon as an opfor popped into view the squad member dropped to a knee, pivoted quickly to aim, and shot the bastard. 4 - i too have been shot by my own squad, and i think it's because once the ai has been given the "dofire" command they just shoot, regardless of who's in their way. I need to think of a way around that one! 5 - I'm delighted that your performance didn't suffer, even if your game didn't improve :) Maturin, can you please try setting up a small editor mission with your player as leader of a small blufor squad, and sprinkle a few opfor around a small town somewhere. That's how i've been doing i and I thought it worked well under those conditions. I'm really grateful for the feedback. Obviously this script is in very early days so feedback can only help improve it. Thanks for PMing that PBO, TPW (acronyms galore).I think I may have found an important bug in the existing script, although I have no scientific tests to offer. I have a dual core 2.53 laptop, so I thought that if anyone can get this script to lag up ArmA, it would be me. I loaded the Ambush mission from my signature, with 100 AI in a single firefight. Yet before I could start in earnest, my own men went crazy and started gunning me down! This mission has the player's squad spread out in pre-set positions across a treeline. Your position spans several hundred meters, and I believe my men may have been seeing each other and somehow identifying their comrades as Unknown rather than Friendly. Then the LOS script told them to open fire on each other. This is my guess, anyways, and would point to a small oversight in the mock-up script rather than a big problem with the new LOS function. I hope my guess is correct, because then it means my mission isn't broken or there aren't deeper issues with LOS. Anyhow, my other CQB observations: AI reaction time is now kick-assingly fast. If I don't use human tricks to outflank them, it is a gunslinger's battle between equals. I can't state this too confidently, since the AI was always capable of near-instant kills, yet never did it consistently. But I ran without ACE and ASR and the AI did not suffer for it in CQB at all. The script as is does not really mitigate the AI's worst CQB problems, however: The AI acts stupidly in vanilla by running from cover to cover, even if the player is two meters away aiming a gun at them. This can result in AI running past or into the player at a defenseless sprint, and as I understand it, this is what the script was supposed to interrupt. While their fruitless dashes between cover may be getting interrupted by the script, it doesn't really happen fast enough, and I don't see them kneel to shoot very often. They will still spend their last seconds on earth running in plain view of the player, and won't stop to shoot if traversing a door in a wall or something. If the script is making them stop their run for cover, it isn't doing it fast enough, and it is actually easier to shoot someone who runs into the open and stops, rather than someone who sprints circles around you and keeps sprinting. The effect of this is that when you shelter inside a compound or courtyard, assaulting AI still expose themselves to your fire in the old way, rather stopping to shoot the moment they make contact. Forcing them to shoot when they have LOS doesn't fix the vanilla glitch of glacially slow aiming. They can still take multiple seconds to drag their gun barrels twenty degrees to the right. And I tested a firefight with four full squads of enemies (4 USMC Rifle and 4 RU Infantry), with no noticeable change in performance. I have an FPS reporter, so let me know if you want anything more quantitative in a specific situation. Share this post Link to post Share on other sites
CameronMcDonald 146 Posted June 14, 2012 A quick question - does the script negate the camouflage of the detected unit? I.e. if a sniper is in LOS, but concealed, will he still be insta-revealed? Share this post Link to post Share on other sites
tpw 2315 Posted June 14, 2012 Yep. If the unit has LOS to an enemy, he will have a crack at him, even if the enemy is wearing an invisibility cloak. Have a look at SaOk's post a few posts back, there are lots of things that need to be done to crank the realism. This early version of the script was just a proof of principle to demonstrate that the beta LOS functionality could be used to modify AI responses. A quick question - does the script negate the camouflage of the detected unit?I.e. if a sniper is in LOS, but concealed, will he still be insta-revealed? Share this post Link to post Share on other sites
maturin 12 Posted June 14, 2012 (edited) As it stands, AI target recognition at night may get an unwanted boost from the script. Going back to play with it now. It only affects BLUFOR squadmates? Alright, a derp on my part. This makes the script extremely difficult to test, since observing the behavior of the AI will affect the test. I can't watch my subordinates do battle without giving away enemy positions to them. It's much easier to test when enemy AI are using the script to hunt the player down. Also, if it only affects your own squad, my big battle tests may have been misleading. Edit: With a carefully-controlled Shapur test, I can definitely see the stop-crouch in action. There are a variety of results. When I order a unit to Move into a compound containing an unseen enemy, he will stop and shoot. Sometimes he will do the glacially-slow AI turning/aiming mentioned earlier. I wonder if a more developed version of the script to make the AI face the target head-on to reduce this wasted time. When the units are moving to cover in Combat mode, they are much slower to stop and do so less reliably. When they are attempting to follow a team leader that has run ahead, they will stop, crouch and look at enemies, but immediately begin moving, before having a chance to shoot. Edit: Anyhow, I put about thirty men in one BLUFOR squad to try and track an enemy in Shapur village. Presumably there were a lot of LOS checks going on, but there was no FPS catastrophe. Also, their fire discipline still prevents blue-on-blue. Edited June 14, 2012 by maturin Share this post Link to post Share on other sites