The Real Bunc 137 Posted May 5, 2019 DynamicCamo (Updated Version 1.5 ) 17/5/19 What does it do? It takes account of players stance, uniform and environmental factors to adjust the players and/or AI unitTrait CamouflageCoef and audibleCoef A low camouflageCoef and audibleCoef gives greater camouflage to the unit and makes it harder for ai to see and hear you. Units appear to be created with camouflageCoef set t0 1 as default. This script dynamically resets this depending on a number of factors. It does this each time player changes stance and at set intervals. This is not just a "stealth" or Ghillie script and will provide camo benefit in all infantry combat. No distinct handling of urban environment at this time. Maybe later. Why? Player may feel AI are not sufficiently impaired in detecting player by factors such as uniform camo, light level, rain, Overcast level, Fog, and Wind, and Trees, Bushes and rocks near player. Script allows player to determine what impact these factors will have on AI ability to detect player or ai unit by sight and sound. It does not alter AI ability to detect movement. When the script is run on an ai unit it impacts the ability of other ai iunits to see or hear that uit depending on environmental factors etc just as for player. What influences the Dynamic Camo? Units stance, units uniform, Fog, Rain, Overcast, light level,wind and bushes or trees and some other objects ( rocks, telephone poles so far) adjacent to unit. Changes happen automatically on change of stance (a minimum 3 second cooldown is built in.) and at scheduled intervals of around five seconds. Can the effect be adjusted ? User can adjust impact of the Dynamic camo by passing the range for the impact for both caounflageCoef and AudibleCoef . These are passed as arguments when calling the script. See guide to adjusting the effect. Installation Copy script as camoscript.sqf to mission folder. In player init ( and/or the init of any other ai unit you want to have dynamicCamo running on) put camo = [this, "DEBUG", 0,1,0,1,5] spawn compile preprocessFile "camoscript.sqf"; will run script in DEBUG mode with a five second recalc delay and a full effect.. Remove DEBUG to turn off and just play. IMPORTANT - the script monitors keys associated with stand/crouch and prone through the use of User1. It will work if you don't do this but you will only get the automatic calculation every five seconds and not the additional stance change triggered recalculation. Go to the menu - controls>custom controls > User1 and ensure you set both the prone key AND the crouch stand key for User1. ( usually z and x keys) If you want to use a different User number select User2... User20 as desired, set keys as stated and change User1 to your desired User,n in script. USE You don't need to do anything other than occasionally crouch, stand up , go prone and watch the different camouflageCoef that is being set for you. Try at night V day, with and without rain, fog etc and watch result. In general I am trying to adjust the impact of the various factors so that they combine together sensibly. User can adjust impacts via linearconversion. If anyone doesn't understand anything please ask. Script prints calculated values when DEBUG on. A BRIEF GUIDE TO ADJUSTING THE EFFECT - The impact of the DynamicCamo effect is adjusted through the arguments in the array passed to the script as follows. [this, "DEBUG" , _cLo, cHi, aLo, _aHi, _ad] where _cLo and _cHi set camouflageCoef range and _aLo and _aHi do same for AudibleCoef. So to run the script with debug mode on and AudibleCoef impact switched off and 5 sec recalc delay [this, "DEBUG", 0,1,1,1,5] to run with DEBUG off and maximum camo for both camouflageCoef and AudibleCoef [this, "", 0,0,0,0,5] run with debug off , ten second autocalc delay and dynamicCamo operating across its full rangeo [this, "", 0,1,0,1,10] run with dynamic camo not having an impact greater than a set floor of 0.3 for both CamCoef and Audible Coef with 5 sec recalc delay. [this,"",0.3,1,0.3,1,5] NOTE 1- It takes quite low values of camouflageCoef to make detection quite hard so this version comes with the factors and the result scaled towards that direction. 2 - I am tuning the impact of factors as the script develops. If you want to try your own tuning try the graph calculator link below then adjust linear conversion output ranges or specific values ( eg for stance) as required. The values currently in the script give a fairly good out of the box result though. Further Development Plans 1) make specific calculation for audibleCoef- done.2) weighting for unit being near bush(s) - done 3) same for tree(s) 4) parameterise adjustables so that they are supplied by array? done 5) handling of weighting for uniform ( ie ghillie suits etc) done ( may upgrade further) 6) test and weight for inside building 7) useable for squad and other ai. (partly done) 8 ) consider MP and JIP compatibility. Version/ Update Notes This is an annotated fully working version. I trust the annotations make the script self explanatory. Version 1.1 - included setting of audibleCoef. Make unit harder to hear. Separate scaling of effect for audibleCoef to allow user to define how much they want impact on audibleCoef. Version 1.2 - handling of light level significantly improved around dawn and dusk. Light level impact adjustable via linearconversion. Version 1.3 - audibleCoef calculation now uses specific factors which can be weighted separately from those for camouflageCoef. Other tweaks include adjustment of range values Version 1.4 - 1) script now auto recalcs every 5 seconds as well as on stance change. Soldier can keep lower stance camo max five seconds on bob down and up. 2) calculated values shown by systemchat and hint for camouflagecoef , audiblecoef and number of trees/bushes/hides found in 2m radius. Turn of by setting DEBUG to empty string in call ie camo = [this,"DEBUG"] spawn etc. See installation. 3) calculation now influenced by near proximity of trees bushes and hides to player. 4) sleep after stance change calculation shortened to 2s for better responsiveness. Version 1.5 1) script now has parameters which can be passed to it allowing easy adjustment of Dynamic Camo impact. See USE. 2) Script now gives different DynamicCamo depending on uniform type. 3) Script works with ai to ai. Ai running the script benefit from DynamicCamo. 4) Recalc interval can be specified per instance of the script. The Script - The script was starting to clutter up this first post so I have removed it. The script is available via the download link for the test scenario at the bottom of this post. If you have any problems getting it from there let me know. All comments welcome. I set up this graphical calculator to show how the function works - just mess with the sliders. https://www.desmos.com/calculator/buiia4zs2j Test scenario mission with v1.5 https://www.dropbox.com/s/xf6x34963ixjue0/camouflagescript.Altis.zip?dl=0 Watch camo level change on stance change. Watch values change as you move about (script in this version also shows opfor man knowsabout unit value with debug set.) Try to escape across the patrolled fields. For me the effect is a bit strong at this point but you can change values in script call. See adjusting the effect above. Make sure to set User1 keys to x and z as instructed above before playing or recalc on stance change wont work. Sept 2022 - Now available on steam Workshop as a MOD whcih autoruns on player unit at teh start of any scenario, ,mission etc with standard settings giving a reasonable camo impact. THis autorun dynamic Camo can be stopped and mission makers can still use their own parameters or mess with debug mode using the mod. 16 2 Share this post Link to post Share on other sites
Tankbuster 1746 Posted May 5, 2019 This is really cool. Does it work as expected in multiplayer? The setUnitTrait command is effects local, so I think this might need some remote execution magic for it to work in MP. Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 I've only ever scripted for SP so I can't really say re MP. I would need advice to ensure it's MP compatible. Glad you like it. Just had a bunch of CSAT set on a S&D WP walk all around me without detecting me on a windy rainy night. I'd like to include uniform checks but I' d need to bone up how to do that sort of thing first. 1 Share this post Link to post Share on other sites
zagor64bz 1225 Posted May 5, 2019 2 hours ago, The Real Bunc said: I'd like to include uniform checks That will wrap up an already awesome script. 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 Thanks for your encouraging comments. Don't get too excited too quickly about uniforms Zagor - I haven't a clue where to start just atm with that sort of thing so Ill be researching it for a bit first. Meantime Im testing including setting the unitTrait audibleCoef - this makes a unit harder to hear. Its a fairly easy update I think. I'm going to take the same calculated value and use it to set audibleCoef but allow for specific rescaling for that factor distinct from the rescaling for the visibility one. I should be updating this fairly soon. 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 Now updated to Version 1.1 to include setting of audibleCoef which should also make your unit harder to for AI to detect by hearing. 1 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 Ok, possible brainwave - what if I also included a check for a nearby tree/ bush ( say within 0.5 metres and had this adjust camo level as well? So youd get better dynamicCamo crouching beside a bush compared to crouching in the open? Id be testing for nearest objects within 0.5 m and filtering for tree or bush present. This is doable? 1 Share this post Link to post Share on other sites
Tankbuster 1746 Posted May 5, 2019 4 minutes ago, The Real Bunc said: Ok, possible brainwave - what if I also included a check for a nearby tree/ bush ( say within 0.5 metres and had this adjust camo level as well? So youd get better dynamicCamo crouching beside a bush compared to crouching in the open? Id be testing for nearest objects within 0.5 m and filtering for tree or bush present. This is doable? Yes, it's very doable. Nearestterrainobjects is your friend. Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 It certainly looks like it Tankbuster. My notion atm is that a check within say a 1m radius shouldn't incur too much overhead. If I detect zero trees or bushes then it will give no effect with increasing effect probably for the number of trees and bushes found near the player. Maybe bushes should get more weight than trees? After all bush foliage is generally at player height whereas tree foliage isn't. Ill probably tackle this next while I'm thinking about handling uniform camo ( I have ideas) . The weights may need some readjustment after such additions as well so this may take me a day or two. 2 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted May 5, 2019 This is a pretty nice work The Real Bunc ! Thank you very much for sharing ! 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 I'm just Bunc really but that was taken. Its my contribution back to this awesome community. I'm hoping someone will hold my hand as I try to implement checks for uniform types so I'm hoping some of you guys will give me advice as I proceed, 1 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted May 5, 2019 I don't know if this helps , i'm using this fnc in my Temperature Script : Spoiler On 12/4/2010 at 7:01 AM, CarlGustaffa said: X_fnc_SunElev = { /* Author: CarlGustaffa Description: Returns the suns altitude for current day and hour of the year on any island (whos latitude may differ). Parameters: None needed. Returns: Suns altitude in degrees, positive values after sunrise, negative values before sunrise. */ private ["_lat", "_day", "_hour", "_angle", "_isday"]; _lat = -1 * getNumber(configFile >> "CfgWorlds" >> worldName >> "latitude"); _day = 360 * (dateToNumber date); _hour = (daytime / 24) * 360; _angle = ((12 * cos(_day) - 78) * cos(_lat) * cos(_hour)) - (24 * sin(_lat) * cos(_day)); _angle }; 3 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 That's very interesting George. At this point ive a feeling sunrise and sunset may be more straightforward ( no doubt mainly because Im already familiar with this approach) . Ill set dusk and dawn as intermediate values between day and night and test for them by looking for time between time say one hour before and one hour after sunrise and sunset. That's my plan for improving that bit but ill have a detailed look at what you posted in case its better for my purpose. I suppose I could time profile both sets of code to find out which is quickest. 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 5, 2019 George - actually if im right your script gives a continuous function whereas Im using stepwise function. Yours is exactly what I was looking for - a continuous function that would give me a number I could convert to a dark light value. Im goimng to rip into that code snippet of yours and see if I can use it that way. Thank you very much! 1 Share this post Link to post Share on other sites
Tankbuster 1746 Posted May 5, 2019 3 hours ago, The Real Bunc said: It certainly looks like it Tankbuster. My notion atm is that a check within say a 1m radius shouldn't incur too much overhead. If I detect zero trees or bushes then it will give no effect with increasing effect probably for the number of trees and bushes found near the player. Maybe bushes should get more weight than trees? After all bush foliage is generally at player height whereas tree foliage isn't. Ill probably tackle this next while I'm thinking about handling uniform camo ( I have ideas) . The weights may need some readjustment after such additions as well so this may take me a day or two. A nearestterrainobjects check of 1m with sort turned off is almost overhead free. The performance impact would be negligible. 2 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 6, 2019 I got to further thinking about using a continuous function for the dark light value. After some tinkering I came up with this that will suit my purpose. 1- (0.5 * cos( (2pi x)/24) -0.5) {x>=0} {x<=24} ( ie where x is the hour) This formula doesn't account for precise sunset and sunrise hours but I'm not sure these are vital given that this is only one factor in the script among a number. I will be including this in the script tomorrow as version 1.2 You can see the shape of this function here https://www.desmos.com/calculator/w8adzn08sl 2 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 6, 2019 Think ive got a better function for the dark/light. It has a sharper light fall of for sunrise and sunset which I can adjust. I need to work out how to convert the values so that it will take sunrise and sunset times as inputs though to get the best out of it. Im going to implement this one rather than the one I posted in my last post. You can see the difference in them here. its the second of the graphs. the value can be animated to show how sunrise and sunset could adjust the crossings ( y=0) the values currently aren't intuitive so some adjustment needed to allow a sunrise or sunset time to give the appropriate adjustment value ( a in the graph) https://www.desmos.com/calculator/pcszjqsc2p 2 Share this post Link to post Share on other sites
GEORGE FLOROS GR 4207 Posted May 6, 2019 On 5/5/2019 at 3:15 PM, zagor64bz said: That will wrap up an already awesome script. What was the other script Zagor ? Just curious ! Share this post Link to post Share on other sites
zagor64bz 1225 Posted May 6, 2019 58 minutes ago, GEORGE FLOROS GR said: What was the other script Zagor ? Just curious ! What I meant was that adding uniform parameters (ie ghillie suits, proper camo pattern ecc ) on what he already put in the script will make it almost perfect. 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 6, 2019 I don't suppose anyone fancies having a go at the shortest possible code snip that will identify a uniform and assign a value in range 0 to 1 to reflect its camo value? If any kind soul did this I would credit it in the script and blurb and I could drop it in. I wont get round to that part until I've finished improving the dark/light factor and then im going to implement a bush/tree test for a foliage /forest campo factor. On that subject - is there any way to test grass level? Share this post Link to post Share on other sites
johnnyboy 3795 Posted May 6, 2019 If you like, consider adding whether someone is in shadows, or in a building to affect the camo factor. Contact @froggyluv, as he has some code somewhere for that in his EGO mod. It solved the very annoying problem of AI instantly spotting you in a building window. 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 6, 2019 Thanks JohnnyBoy - I will do. Ill think about implementing those suggestions, my sequence atm will be improved daylight function, presence of trees/bushes factor, uniform factor. Do you think being in a building should make it hard for ai to see you? It should from the outside but doesn't geometry take care of that? I suppose thinking about it , during the day a building will be relatively dark inside so maybe that combination should indeed produce more difficulty for ai to see you. I suspect testing for a shadow will be fairly hard. It would require - sun angle ( George's Sun elevation snippet above does that) but and also the height of the objects casting shadows and the relative positions and angles of near objects to the player. Im not aware of any direct test of illumination level at a position. If there was that would be ideal of course. I'll contact FroggyLove as you suggest. Thanks. 1 Share this post Link to post Share on other sites
froggyluv 2136 Posted May 7, 2019 Normally I dont talk to strangers see....but..since JohnnyBoy sent yas J/K -PM Sent 2 1 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 7, 2019 Im not sure if anyone is interested in the function fitting stuff I'm doing but I'm going to post it anyway. It gives me a reference back to it anyway. Ive been working further on the function for daylight and have now refined it further. In the following animated graph c would be the sunrise time returned by the sunrisesunset function. I then adjust this with an adjustment factor ( c) in the graph to get crossing points where I want. Im going to do final tuning of this I think by checking earliest and latest sunrise times for the year in the game on altis and then tune the final figures to get the best representation I can. I'm getting close now to this working. Once i've got good values pinned down Ill do the implementation. The function is nice and short and hopefully good enough , and certainly better than a step function. anyway here it is https://www.desmos.com/calculator/vtt1zqq6hz 2 Share this post Link to post Share on other sites
The Real Bunc 137 Posted May 7, 2019 Well after all attempts to get some sort of continuous function to represent a light level factor Ive decided to go back to a stepped function. Even though the continuous functions wasn't bad it still was clunky when trying to cope with the light change around sunrise and sunset. I realised tha a piecewise function is actually not only easier but actually can do this much better. Ive now modelled this in the graphical software and Im much happier that ive nailed this down now. I now know what conditions I need to test, what variables I will need and which bits can be user influence ( dark level floor and range adjustment within 0,1) So my next step is implementation. That should be much easier now Ive clearly got those bits nailed down. Here it comes. Yes another graph. But this one is fun. Play with the sunrise and sunset times and dark level. At the moment Ive set a two hour transition from dark to light centered on sunrise time and also on sunset time. I had it at one hour but that was a bit short. Anyway here's the graph for the playful. Now to code it. https://www.desmos.com/calculator/hzb70nlxsi Update: I just realised we have a boundingboxreal command where I can get the outer points of the bounding box of a building. extra cam for being in a building would be - test for nearest building within some distance ( say 4m) > for each building obtain outer points of bounding box x, y, z > test if unit is within the 2d area> if yes provide camo factor. I don't think a test for within volume will provide much more benefit than a test for unit within area unless I go for something really sophisticated like testing if on different floors , roof etc. But im aiming to keep this real lightweight if I can. Ha just realised I'm thinking out loud on here. Apologies. 2 Share this post Link to post Share on other sites