Jump to content
Sign in to follow this  
Pioneer760

Making AI do moves while standing guard

Recommended Posts

Hi Editing folks,

Help is much appreciated for following issue:

Objective:

Making AI soldiers (standing guard and being idle) do extra moves to increase immersion (e.g. exercises kneeling, pushups, fixing weapon/ boot laces, etc.) BUT without disabling their ability to detect and respond to enemy present.

So far:

I used the Post Guard script to let them scan different directions and added extra moves. But AI wont detect enemies or respond to shots fired at them (reasonably fast) while doing moves and get stuck later sometimes.

BIS Simple-Guard-Post-Script&highlight

My core code so far:

// Start scanning 
while {alive _unit} do		// loop while unit is alive
{
hintsilent str (_unit knowsAbout player);

if (_unit knowsAbout player > _knowsAboutThresh) then      //in case of detected enemy present unit should not go into watching or animation mode but fight	
	{
	// unit should get into the right AI fighting mode
	_unit selectWeapon primaryWeapon _unit; //to avoid unit fighting with pistol despite not having one due to animation/move that required shouldered primaryWeapon
	_unit setBehaviour "COMBAT";
	_unit setUnitPos "AUTO";
	_unit enableAI "WATCH";
	_unit enableAI "MOVE"; 
	_unit switchmove "";		// switching to random move without delay/ aborting move quickly		
	_unit enableAI "TARGET";
	_unit enableAI "AUTOTARGET";
	_unit enableAI "ANIM";		

	}
   else		// this is the normal guard/scanning and do move mode 
   	{	

	// 1. setting and 2. reseting values in case unit calms down after being alert (knowsabout less then knowsaboutthreshold)
	if (_range < 0) then {_range = 0};
	if (_range > 360) then {_range = 360};
	if (_beh == "CARELESS" || _beh == "SAFE" || _beh == "AWARE" || _beh == "COMBAT" || _beh == "STEALTH") 
	then
	{_unit setBehaviour _beh} else {_unit setBehaviour "SAFE"};
	_unit setUnitPos _stance;


	// Preparation of Watch in direction
	_left = _startdir - (_range/2);
	_right = _startdir + (_range/2);

	if (_left > _right) then {_left = _startdir - (_range/2); _right = _startdir + (_range/2)};	

	_left = round _left;
	_right = round _right;

	_dir = random (_right - _left) + _left;
	if (_dir < 0) then {_dir = _dir + 360}; 

	_pos  = position _unit;
	if (_height) then {_zaxis = random 20};
	if (!_height) then {_zaxis = _pos select 2};
	_pos = [(_pos select 0) + 50*sin _dir, (_pos select 1) + 50*cos _dir, _zaxis];

	_unit doWatch _pos;

	//animation moves

	_sel = floor(random(((count _Anim)+1) -0.5 ));	//number of animations in the array, randomly selected and changed into an integer number
	_unit playMove (_Anim select _sel);

	//this loop should abort the animation in case the unit gets to know more about the player during animation 
	while {(animationState _unit) == (_Anim select _sel)} do 
		{
		if (_unit knowsAbout player > _knowsAboutThresh) exitWith {

			_unit enableAI "ANIM";
			_unit enableAI "MOVE"; 
			_unit switchmove "";		// switching to random move without delay/ aborting move quickly
			_unit selectWeapon primaryWeapon _unit; //to avoid unit fighting with pistol despite not having one
			_unit setBehaviour "COMBAT";
			_unit setUnitPos "AUTO";
			_unit enableAI "WATCH";
			_unit enableAI "TARGET";
			_unit enableAI "AUTOTARGET";
			};
		};

	_wait = (random 10) + _delay;
	sleep _wait;

	};
};

How can I do it better / make AI respond faster while doing a move?

Cheers

I am currently improving my mission:



SP-Operation-Ridge-Sweep--A3v01

OM_A3v01_01.jpg

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  

×