Jump to content
Sign in to follow this  
engima

AI visibility value

Recommended Posts

Hi!

I am looking for a way to find out how good visibility AI (and player) have in "current ciscumstances". What I want to do is reveal (script command "Reveal") player group to all enemy units within visual distance, but that distance is a variable distance, depending on current ligth/darkness and weather conditions. Is there an easy way to do that through some fancy script command, or do I have to test all possible conditions (different time of days, fog and rain) to se how good visibility there is?

Share this post


Link to post
Share on other sites

Thing is, I want to manually determine if the enemy units can see the player group before I reveal player group to them. Right now, upon detection, I reveal player group to all enemy groups within 350 meters. I want enemies to react, like they heard the sound, even if they were not in the group that actually detected the players. My solution works fine in daytime and clear weather, but as you understand it works badly in conditions of bad visibility (like heavy fog). So in my script, in some way, I need to know how far the visibility is. The game does this all the time, so I wonder if there is a way for me to get that "visibility value" too?

Share this post


Link to post
Share on other sites

You could just do a simple knowsAbout check.

_kv = enemygroup knowsAbout (leader mygroup);

if (_kv >= 1.5) then {
enemygroup reveal [(leader mygroup), 4];
};

The knowledge value can be 0-4, i think you need to try out differend values to get a optimal result.

Visibility and other stuff should already affect knowsAbout.

Share this post


Link to post
Share on other sites

Thanx for the replies! Please correct me if I'm wrong, but if a unit is 100 m away from me and facing the other direction, isn't its knowsAbout value 0 until he turns around and detects me? It's units like that I would like to reveal myself to immideately. And if its knowsAbout is 0 I cannot use knowsAbout. I want to find out if he potentially *can* detect me, not if he has already.

Share this post


Link to post
Share on other sites

if its simply a distance you want to check for and reveal:

while {true} do {
{
	_unit = _x;
	if (alive _x AND side (group _x) == east) then {
		{
			if ({(_unit distance (vehicle _x)) < 100 AND side _x == west) then {_unit reveal [_x, 4]};
		} foreach allUnits;
	};
} foreach allUnits
sleep 5;
};

code will reveal all west units to all east units within 100 meter every 5 seconds.

Share this post


Link to post
Share on other sites

I simply want "visibility distance". How far can you (or any unit) see in current weather and daytime conditions? The game itself must know that, so is there any script command I can use to fetch that value?

Demonized: In your example, it's your "100" meters I want instead to be "visibility range". (So it will be say 50 meters in really heavy fog, or 300 meters in not so heavy fog.

But I will try knowsAbout since you recommend it, I havn't tried it yet. Maybe it doesn't work the way I have assumed this far. Can a unit know anything about another unit without having seen it?

Share this post


Link to post
Share on other sites

Knowsabout 0, means unit have not seen or heard the unit.

More than 0 means that its detected sound/sight of something.

Above 1 means detected object, unsure what specific kind or side, but even in daylight will a unit standing with its back to you knowsabout you 0, so you will you if i sneak up behind you.

viewDistance is the command to check your ingame viewdistance, but that is generally at 1500 to 10000, wich you can potentially spot something. you just needs to define yourself what range is considered spottable.

you can check daytime and fogaswell i think, but daytime readings are useless if precision is desired as 04:00 in winter is not same as in summer (dark night/bright morning).

this is a function created by CarlGustaffa wich calculates it somewhat but again, not 100% reliable:

       /* Comments by Demonized.
   this below is sun elevation calculations but it gives different values on different times of the year so it will not be 100% accurate
   and was never meant to be, results will vary, hour, weather, island etc effects in, but it gives an estimate.
   great for those missions spanning over day and night and possibly longer, where you dont know if its light(day) or dark(night).
       */
_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"];
	_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
};

Share this post


Link to post
Share on other sites

I remember someone made a LOS check function that sees if a unit has los to something (considers terrain obstruction and objects) you may want to look into that. But as far as I know, there isnt really a way of changing the spotting distance directly in terms of metres.

you can however, try using setskill array, changing spottime and spotdistance:

AI setSkill ["spotDistance", 0.1] AI setSkill ["spotTime", 0.2]

it takes a value from 0 to 1, poor to amazing respectively.

that might be good for very foggy and no visibility.

IF you want this to be something dynamic (as in always adjust ai spotting when weather changes) you would need to write a script that checks current forecast and fog levels, and adjust the spotting in levels of fog density, etc. Use the above function demonized posted to get a rough estimate of nighttime and adjust spotting if its nighttime.

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  

×