Jump to content
gitrinec

Make units aim properly at target during animation

Recommended Posts

Is it possible to keep a unit fireing at an actual target during a walking animation , they are firing with forceweaponfire but just straight ahead , not aiming.  Also what's the smoothest way to break out of forceweaponfire?

Share this post


Link to post
Share on other sites

I have struggled with this myself.  If you force an animation on the unit (playMove/SwitchMove/playAction) the unit cannot target and swivel their upper body toward target while playing the move animation.  I don't think its possible, but I would love to be proven wrong (its a problem with my AI Movement scripts).  For my movement scripts, I put a handleDamage eventHandler on the moving AI to stop his move animation if he is hit, so he can return fire (this could be improved to stop him if he knows about a near enemy and has line of sight to that enemy).  I also try to make the distances he travels using switchMove short, so he has a chance to target and fight known targets soon when he reaches the next destination.  Its possible to change unit's direction while he is playing a move animation, so you could turn him toward target while he is moving, but then he is off course and  not going where you originally wanted him to go.

 

For breaking out of forceWeaponFire, it depends on how you are calling it I guess.  In my Point Blank Melee script, I use forceWeaponFire to double/triple/quadruple tap near AI with a simple forEach loop:

				_nul = [_unit,_weapon] spawn  
				{  
					params["_unit","_weapon"];  
					{  
						_unit forceWeaponFire [_weapon, "Single"];  
						sleep .1;  
					} foreach [1,1,1,1,1,1,1,1,1,1,1,1,1];  
				};

This could easily be a While loop where you set the condition that will end the loop like this:

KeepUnitFiring = false;		
_nul = [_unit,_weapon] spawn  
{  
	params["_unit","_weapon"];  
	while {KeepUnitFiring and alive _unit} do
	{  
		_unit forceWeaponFire [_weapon, "Single"];  
		sleep .1;  
	};  
};

Then you have code elsewhere that sets global variable KeepUnitFiring to false when you want the unit to cease fire.

 

I'm curious how you are using this...?

  • Like 1

Share this post


Link to post
Share on other sites
On 1/3/2020 at 2:43 PM, johnnyboy said:

I have struggled with this myself.  If you force an animation on the unit (playMove/SwitchMove/playAction) the unit cannot target and swivel their upper body toward target while playing the move animation.  I don't think its possible, but I would love to be proven wrong (its a problem with my AI Movement scripts).  For my movement scripts, I put a handleDamage eventHandler on the moving AI to stop his move animation if he is hit, so he can return fire (this could be improved to stop him if he knows about a near enemy and has line of sight to that enemy).  I also try to make the distances he travels using switchMove short, so he has a chance to target and fight known targets soon when he reaches the next destination.  Its possible to change unit's direction while he is playing a move animation, so you could turn him toward target while he is moving, but then he is off course and  not going where you originally wanted him to go.

 

For breaking out of forceWeaponFire, it depends on how you are calling it I guess.  In my Point Blank Melee script, I use forceWeaponFire to double/triple/quadruple tap near AI with a simple forEach loop:


				_nul = [_unit,_weapon] spawn  
				{  
					params["_unit","_weapon"];  
					{  
						_unit forceWeaponFire [_weapon, "Single"];  
						sleep .1;  
					} foreach [1,1,1,1,1,1,1,1,1,1,1,1,1];  
				};

This could easily be a While loop where you set the condition that will end the loop like this:


KeepUnitFiring = false;		
_nul = [_unit,_weapon] spawn  
{  
	params["_unit","_weapon"];  
	while {KeepUnitFiring and alive _unit} do
	{  
		_unit forceWeaponFire [_weapon, "Single"];  
		sleep .1;  
	};  
};

Then you have code elsewhere that sets global variable KeepUnitFiring to false when you want the unit to cease fire.

 

I'm curious how you are using this...?

I'm doing this with it, but as you are aware they just shoot straight.  Even using _unit disableAI "PATH" over  _unit disableAI "MOVE" doesn't change anything. But so far I'm able to keep them shooting in a line while walking. But looks awful when there is a wall behind the object they are shooting and they mostly just hit the wall.

 

 

6444a84e779d8768365d5dd7abe66502cfa26603

 

Share this post


Link to post
Share on other sites
2 minutes ago, gitrinec said:

I'm doing this with it, but as you are aware they just shoot straight.  Even using _unit disableAI "PATH" over  _unit disableAI "MOVE" doesn't change anything. But so far I'm able to keep them shooting in a line while walking. But looks awful when there is a wall behind the object they are shooting and they mostly just hit the wall.

 

Nice screenshot anyway.  Another possibility is to create an invisible target in front of them.  Be sure the target belongs to an enemy side of shooters, reveal the target to the shooters.  DisabelAI "FSM", setUnitPOS "UP" and commandMove them to points ahead of them.  They just might move and shoot.  A guy can dream anyway.

Share this post


Link to post
Share on other sites
13 minutes ago, johnnyboy said:

Nice screenshot anyway.  Another possibility is to create an invisible target in front of them.  Be sure the target belongs to an enemy side of shooters, reveal the target to the shooters.  DisabelAI "FSM", setUnitPOS "UP" and commandMove them to points ahead of them.  They just might move and shoot.  A guy can dream anyway.

I don't have an invisible target but an actual target with reveal, dotarget, commandtarget, dofire, lol .  Also DisableAI "FSM", setUnitPOS "UP"  is set.  Though I did see them one time actually turn some but then they shot one of their own , lol..  I did notice in 3DEN enhanced there is a option to disable weapon aim   .  - attribute to disable weapon aim for AI units..    the usual _unit disableai "WEAPONAIM" - no weapon aiming.  But enableAI "WEAPONAIM" didn't change anything. 

Share this post


Link to post
Share on other sites
2 hours ago, johnnyboy said:

Nice screenshot anyway.  Another possibility is to create an invisible target in front of them.  Be sure the target belongs to an enemy side of shooters, reveal the target to the shooters.  DisabelAI "FSM", setUnitPOS "UP" and commandMove them to points ahead of them.  They just might move and shoot.  A guy can dream anyway.

So this seems promising, I found it as a Arma 3 feature request .  Maybe it's just me but my AI seem to hit the target more.  The poster of the code Leopard20 mentioned that it wouldn't allow the AI to aim up and down.  Can you see if this makes your ai hit anything?   I didn't use it exactly as it was, just added it in my code.    

 

https://feedback.bistudio.com/T144528

[] spawn {
  _lastDir = 0;
  aiTarget disableAI "ALL";
  ai setSkill 1;
  ai disableAI "MOVE";
  ai doWatch aiTarget;
  ai doTarget aiTarget;
  aiTarget allowDamage false;
  _time = time+3;
  waitUntil {
    ai playMoveNow (["amovpercmtacsraswrfldl", "amovpercmtacsraswrfldr"] select _lastDir);
	ai forceWeaponFire [currentWeapon ai, currentWeaponMode ai];
	ai reveal aiTarget;
	if (time - _time > 3) then {
		_time = time;
		aiTarget attachTo [ai, [0, 5, ([2, 5] select _lastDir)]];
	};
	_lastDir = 1 - _lastDir;
	ai setAmmo [currentWeapon ai, 10];
   sleep 0.3;
    false
  }
};

c348a1debcacd661e3c2b98f8823e77af2432446

Edited by gitrinec
Added image
  • Like 1

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

×