Jump to content
Undeceived

Is it possible to make the AI to aim at a certain point of its aiming deadzone? / Make AI to target position / target immediately via script

Recommended Posts

Hi guys,

 

as Arma's AI sometimes lets us down, now and then one has to come up with dirty (scripted) workarounds. :glare:

 

I want to make an AI to shoot an AT rocket at a tank (everything scripted as it has "ANIM" disableAI'd). So I set the unit up this way:

 

//Take out rocket launcher
ws3 playMove "AmovPknlMstpSnonWnonDnon_AmovPknlMstpSrasWlnrDnon"; //As selectWeapon doesn't work as intended for AT-launchers I have to play this move and disableAI "ANIM" to prevent the AI to select the rifle again.
ws3 disableAI "ANIM";

sleep 3;

//Set unit to face target - horizontally only though :-(
_dir = [ws3, target] call BIS_fnc_dirTo; 
ws3 setDir (_dir);

//Fire
ws3 selectWeapon (secondaryWeapon ws3);
ws3 fire [weaponState ws3 select 1, weaponState ws3 select 2, weaponState ws3 select 3];

 

 

And now the obvious problem: As the target is to far away from the shooter, the rocket will hit the ground only.

 

Is there a way to automatically and immediately (via script) make the AI to point the weapon in the right direction, e.g. on a game logic above the tank? This would solve the problem, but I don't know how to set a vertical direction via script - I only know how to set the right horizontal direction (see my code above).

 

Any ideas?

 

As said, I need a scripted (immediate) solution, no "command" commands such as doTarget or lookAt, etc. Two reasons: 1: AI can't move ("ANIM" disabled") - 2: By using these I would again rely on the AI which I want to avoid. 

Thanks for your help!

 

 

EDIT:

Thinking more about the subject I changed my question rather towards "how to make the AI to aim at a certain point of its aim deadzone".

Share this post


Link to post
Share on other sites

Why would you disable "ANIM" ? There are usually better options.

 

Disable "PATH" if you want them to stay in one spot.

Target commands do work very well if you eliminate anything that could distract them ^^.

 

 

 

Use a combination of the following and make sure they have their weapon out / aimed at the target beforehand.

disableAI "PATH"

disableAI "AUTOTARGET

setCombatMode "BLUE"

setUnitPos "UP"

reveal

doTarget

 

 

Then just give him a fire command and the reaction should be pretty much immediate.

 

Share this post


Link to post
Share on other sites

The problem is that selectWeapon (secondaryWeapon unit) doesn't work - I think it's bugged. The AI selects the rifle immediately (or if the AT launcher is its only weapon nothing will happen). This is why you need the ANIM disabled. This way the launcher stays in the unit's hands and you can work with the fire command.

 

I found a dirty workaround of the dirty workaround by appliyng BIS_fnc_setPitchBank to the unit in the moment before the shot is fired. Well, it's a bad solution as the whole body is lifted for a moment.

 

So the main question would be: Is it possible to set the AI to aim at a certain point of its aiming deadzone?

 

tumblr_mbfkvikLJa1qh2s93.png

Share this post


Link to post
Share on other sites

How about changing z velocity of missle?  I did that in Property of Mabunga, where I had a static enemy launcher fire on the CSAT zodiacs.  I wanted the shots to fly overhead for excitement, but not actually hit the zodiacs.  So I used a Fired eventHandler, and reset z velocity.  AI would target and fire, but z velocity change guaranteed missle flew high.  I also reduced speed of missle so it was more fun to watch.

{
    _x addEventHandler ["Fired", {
        _null = _this spawn {
            _missile = _this select 6;
            _vel = velocity _missile;
            _dir_modifier = -3.5 + random(6);
            if (_dir_modifier >= -1 or  _dir_modifier <= 1) then
            {
                _dir_modifier = _dir_modifier * 2;
            };
            _dir = direction _missile;
            _speed = speed _missile;
            _speed = _speed / 3;
            _z_modifier = 2.5 +     random(3);
            _missile setVelocity [_speed * sin(_dir), _speed * cos(_dir), (_vel select 2)+_z_modifier];
            };
    }];
} foreach [rocketMan1];

 

Share this post


Link to post
Share on other sites

Great idea, JB! Thanks a lot. This should do it and even look quite decent. :icon_biggrin:

 

Cheers!

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, Undeceived said:

The problem is that selectWeapon (secondaryWeapon unit) doesn't work - I think it's bugged. The AI selects the rifle immediately (or if the AT launcher is its only weapon nothing will happen). This is why you need the ANIM disabled. This way the launcher stays in the unit's hands and you can work with the fire command.

 

I found a dirty workaround of the dirty workaround by appliyng BIS_fnc_setPitchBank to the unit in the moment before the shot is fired. Well, it's a bad solution as the whole body is lifted for a moment.

 

So the main question would be: Is it possible to set the AI to aim at a certain point of its aiming deadzone?

 

The only command / function allowing an aiming "in the air", with no target is doSuppresiveFire waiting for simple coordinates.

You can test it, with forceWeaponFire to select the launcher but there is no target so far and the missile isn't fired.

It's just a mean to point at some coordinates and select the launcher.

Then you have to create the missile by createVehicle with the position and launcher orientation.

 

Just test, on AT man named bob:

 

0 = [] spawn {
  bob doSuppressiveFire (bob modelToWorld [300* cos (getDir bob),300 * sin (getDir bob),300]);
  bob forceWeaponFire ["launch_B_Titan_short_F","single"];
  sleep 3.5;
  _vector = eyeDirection bob;
  _vectordir = [(_vector select 0), (_vector select 1), 0];
  _vectorup = [-(_vector select 0), -(_vector select 1), 90 - (_vector select 2)];
  _missile = "M_Titan_AT" createVehicle (bob modelToWorld [2* cos (getDir bob),2 * sin (getDir bob),2]);
  _missile setVectorDirAndUp [_vectordir,_vectorup];
};

 

Remaining problem: my vectorUp is wrong. I didn't succeed in pitching the missile; If anyone could help...

 

 

 

Share this post


Link to post
Share on other sites

Finally, I got it. play with 3rd param of modelToWorld for adjustment of missile pitch:

 

0 = this spawn { sleep 3;
  _this doSuppressiveFire (_this modelToWorld [0,300,300]); 
  _this forceWeaponFire [secondaryWeapon _this,"single"]; 
  sleep 3.2; 
  _vector = _this weaponDirection currentWeapon _this; 
  _dir = getdir _this; 
  _pitch = sqrt ((_vector select 0)^2 + (_vector select 1)^2) atan2 (_vector select 2); 
  _missile = "M_Titan_AT" createVehicle (_this modelToWorld [2* cos (getDir _this),2 * sin (getDir _this),2]); 
  _missile setDir _dir; 
  [_missile,_pitch,0] call BIS_fnc_setPitchBank; 
};

 

Just lack of sound...

Share this post


Link to post
Share on other sites

You can also use a fired eventhandler to guide unguided rockets if you really want to make sure they hit. ;)

 

Anyway, I'd still stick with the more traditional method and let the AI take care of the aiming and shooting. Less magic involved usually makes better or at least more flexible missions.

 

Switch the weapon with this instead of the selectWeapon command:

https://community.bistudio.com/wiki/ArmA:_Actions#SWITCHWEAPON

Share this post


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

Anyway, I'd still stick with the more traditional method and let the AI take care of the aiming and shooting. Less magic involved usually makes better or at least more flexible missions.

 

All in all I agree with you but there are situations that are not flexible and where one can't rely on the AI's behaviour systems. The situation we're discussing here is set in a cutscene. The part with the AT shot is approximately 1,5 seconds long, which means I need the AI shooting and hitting the tank 100% in the right moment.

 

Other than that I'll try out your suggestion with the switch weapon action.

Share this post


Link to post
Share on other sites
4 hours ago, Undeceived said:

Other than that I'll try out your suggestion with the switch weapon action.

 

Did u try my script?

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

×