Home   Help Search Login Register  

Author Topic: AI helicopter crash avoidance  (Read 1904 times)

0 Members and 1 Guest are viewing this topic.

Offline UH60MG

  • Members
  • *
AI helicopter crash avoidance
« on: 16 Nov 2008, 10:20:20 »
Anyone noticed that the AI will often crash a helicopter into a tall tree or building once it switches to combat mode? This script should reduce this occurance significantly.

It's a fairly simple but effective script.

Usage: [ _veh ]exec "KeepHeight.sqs" - where _veh is the helicopter you want to not crash

N.B: Increase _height variable if helicopter still crashes, which may still happen over mountainous terrain.
« Last Edit: 16 Nov 2008, 10:24:52 by UH60MG »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: AI helicopter crash avoidance
« Reply #1 on: 16 Nov 2008, 12:11:01 »
Even if it is for a single small script, please, try to include a basic demostrating mission with it.

And now about the script itself. You may try to use a Sleep 1 or even Sleep 2 (or ~2) when checking for height, and once the condition is met, use a much faster loop. A chopper cannot dive too fast, so a slow loop with be much better to detect the < height condition, while you need a quite fast loop to initiate the climb avoidance. This way your script would be much more effective performance wise. Also take into consideration locality of the unit, as setVelocity will work only on local units.



Here is a sqf example of that:
Code: [Select]
/*
Usage: [ _veh, 40 ]execVM "KeepHeight.sqf"
Where _veh is the helicopter you want to not crash
Second parameter is minimum allowed height over ground

N.B: Increase _height variable if helicopter still crashes, which may still happen
over mountainous terrain.
*/


private["_veh", "_height"];
_veh = _this select 0;
_height = _this select 1;

while {(canmove _veh) && !(isPlayer (driver _veh))} do
{
   if ((getPos _veh select 2) > _height) then
   {
      Sleep 1;
   }
   else
   {
      if (local _veh) then
      {
         _veh setvelocity [ velocity _veh select 0 , velocity _veh select 1 , 1 ];
      };
      Sleep 0.01;
   };
};