Jump to content
Wiki

AI does not fire at practice target

Recommended Posts

Hi.

Got a problem: the AI does not fire at practice target.

 

  • I put a practice target named target1
  • I put an AI
  • In init field of the AI: this dotarget target1; this dofire target1
  • the AI targets the practice target but does not fire at it
  • If I put another unit instead of the practice target, the AI will fire at it

 

So, how can I get the AI fire at the practice target?

 

Thanks

 

Share this post


Link to post
Share on other sites

You will need to use Forceweaponfire https://community.bistudio.com/wiki/forceWeaponFire  it's no ideal but it kind of works.

I don't think it uses the AI calculations so sometimes it's a bit off.

 

I really hate that you can't just mark any target a treat and have AI shoot at it using true calculations, it's very strange for a shooting based game that  makes it difficult to shoot things.

  • Like 1

Share this post


Link to post
Share on other sites

Just tried, doesn't work.

 

I used forceweaponfire command and fire command and nothing.

 

It's weird cause it used to work before, even just dotarget and dofire but id no longer does now.

Share this post


Link to post
Share on other sites
8 hours ago, Wiki said:

Just tried, doesn't work.

 

I used forceweaponfire command and fire command and nothing.

 

It's weird cause it used to work before, even just dotarget and dofire but id no longer does now.

It's working for me man

dotarget target; 0=[] spawn {sleep 1.5; 0 = man forceWeaponFire [currentWeapon man,"single"]}

 

Share this post


Link to post
Share on other sites
5 hours ago, f2k sel said:

It's working for me man


dotarget target; 0=[] spawn {sleep 1.5; 0 = man forceWeaponFire [currentWeapon man,"single"]}

 

 

Well, it works, but one time only.

The unit fires a single shot and that's all.

What I'm looking for is for the unit to fire at the target and reengage it.

Share this post


Link to post
Share on other sites

Well you would need to place it in a loop but then you may want it choose different targets ect

The best thing would be to look for a Shooting range script many have been made.

Share this post


Link to post
Share on other sites

Use BIS_fnc_fire - that should work in any case.

 

/edit: And yeah, you will have to put it into a simple loop.

Share this post


Link to post
Share on other sites

Now, just just have to hit the target :uzi:

 

In init field of a shooter:

   0 = this spawn {
      while {alive _this} do {
        _this doTarget cible;
        waitUntil {cible animationPhase "Terc" == 0};
        _time = diag_tickTime;
        sleep 2;
        if (_this ammo (currentWeapon _this) == 0) then {_this addMagazine currentMagazine _this};
        if ((_this weaponDirection (currentWeapon _this) vectorCos ((position cible) vectorDiff (eyepos _this))) > 0.999 min (0.975 + (0.00024 *(_this distance cible)))) then {
          _this forceWeaponFire [currentWeapon _this,currentWeaponMode _this];
          waitUntil {cible animationPhase "Terc" == 1 or diag_tickTime > _time + 10};
        } else {
          _this lookAt cible
        };
        sleep 3;
      }
    };

 

Then place a target (moveable like: Target_PopUp_Moving_90deg_Acc2_F) and name it: cible.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Thx, I'll try this ASAP.

Share this post


Link to post
Share on other sites
3 hours ago, pierremgi said:

if ((_this weaponDirection (currentWeapon _this) vectorCos ((position cible) vectorDiff (eyepos _this))) > 0.999 min (0.975 + (0.00024 *(_this distance cible)))) then {

Hey Pierre, that is slick.  I'm terrible at understanding math and vectors.  I get the general idea that this if statement is checking if direction of weapon is pointing at the target object within some tolerance.  But could you break down how this code works?   I don't get how the combination of vectorCos and vectorDiff works, and I don't get how the values to the right of the ">" are used for the tolerance.

 

If its too hard to explain, that's ok too...  :)

Share this post


Link to post
Share on other sites

I tested some values to stay in a cone before AI fires (The AI seems to watch the target but the weapon's direction is always drifting).

The problem is to fire on something without any interest for AI brain. Perhaps, there is an alternate way with doSuppressiveFire, as you can set a position. I didn't waste my time with that.

Anyway, the loop is re-adjusting the weapon's direction with lookAt and doTarget. The fire occurs if the cosine angle between the weapon's direction (weaponDirection) and the target's direction ( difference between 2 vectors: target's position & Ai's position)  is close to 1 (very sharp cone). But this value is "sensitive".

Then, I try to stay above the value 0.975 + 0.00024 * distance target/AI (not exceeding 0.999)

0.975 is cosine (2,5°) , 0.975 is cosine ~ 13° (distance 0 m).  At 100 m , the value are same.

You can work around with that or another method, but it remains hard for AI to shoot with accuracy on a simple target.

Thanks for commenting what you experienced in your trials.

  • Like 1

Share this post


Link to post
Share on other sites

Still couldn't try as I'm not home, but it's weird because the commands "dotarget+dofire" used to work before.

Share this post


Link to post
Share on other sites

I have been trying to do this for about 6 years. My ultimate goal was to have mortars fire so that the rounds would land randomly.

 

I started with an AI rifleman firing at a practice target. I tried many things. The usual result is that he would fire at the target till it was "killed". He would never again at a pop up target nor could I make him fire at a second target.

Share this post


Link to post
Share on other sites

Placing an invisible target in front of a popup target works.   Prove it by placing a player, an AI unit named "dude", and a target in front of the dude named "popup1".  Then via the debug console execute the following code.  The AI will then fire on the invisible target relentlessly.  This approach can be expanded to delete the invisible target when popup is knocked down, and re-add a new one when popup pops back up.  Or you could place multiple targets in a range, and script moving the invisible target from one visible target to another.  Then you would see the AI fire on each target in sequence.

_invisibleTarget =  "O_TargetSoldier" createVehicle [0,0,0];  
createVehicleCrew _invisibleTarget;  
dude setUnitPos "DOWN";  
_invisibleTarget setpos (popup1 modelToWorld [0,0,2]);  
dude reveal _invisibleTarget;  
dude doTarget _invisibleTarget;

 

Share this post


Link to post
Share on other sites
On 10/12/2017 at 10:24 AM, Wiki said:

Hi guys, I'm back.

 

So, I tried the code, but it doesn't work :-(

 

Ticket here

https://feedback.bistudio.com/T127344

Why didn't you try my code? It's working. Place an animated target (it needs terc animation) , named cible, at 100 m of a shooter, stand up, crouch, prone... Simple as that!

 

 

 

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

×