Jump to content
Sign in to follow this  
CMajor28

Avoid Chopper Crash

Recommended Posts

I have this chopper on a mission flying overwatch and it seams to crash between 30 seconds and 5 minutes of starting the mission. How do I make it not crash?

Share this post


Link to post
Share on other sites

Hi CMajor28,

I made a script for my mission (in my sig') to prevent heli AI crash,

the script help the heli AI to fly more safely over any high cliffs/mountains with flyinheight 60 (minimum recommended).

But the script is an sqs.

usage:

[HeliName,60,0.1] exec "flysafe.sqs";

_fu = _this select 0;
_fhd = _this select 1;
_fdy = _this select 2;

_fhtr = "Helihempty" createvehicle (position _fu);
_fus = getPos _fu select 2;
_dy = _fdy *0.5;

#flyck
? (1 < speed _fu) : _fus = speed _fu;
_fhz = getPos _fu select 2;
_fhu = getPosasl _fu select 2;
_fhtg = getPosasl _fhtr select 2;

? (_fhd > _fhz) : _fhs = _fhz +_fus; _fudz = -_fus *_fus; _fhdz = _fhd +((_fhd -_fhz) *2);
? (_fhd < _fhz) : _fhs = _fhd +_fus; _fudz = _fhz *0.1; _fhdz = (_fhz +(_fhd *0.05)) -((_fhz -_fhd) *0.1);
_dfu = getdir _fu;
_ftx = _fhs *sin(_dfu);
_fty = _fhs *cos(_dfu);

_fhtr setpos [(getPos _fu select 0) +_ftx, (getPos _fu select 1) +_fty];
if (_fhtg +(_fhd *0.5) > _fhu) then {_fu flyinheight ((_fhtg +(_fhd *0.5)) -_fhu) +(_fhd *1.2); _fu limitSpeed _fudz} else {_fu flyinheight _fhdz; if (_fhd *0.6 > _fhz) then {_fu limitSpeed _fudz} else {_fu limitSpeed _fus *(1 +((_fhu -_fhtg) *0.002))}};
~_dy
if (alive _fu) then {goto "flyck"};

deletevehicle _fhtr;
exit

Edited by Morieza

Share this post


Link to post
Share on other sites

If you really want to control how your helicopter flies to a t, than use this method:

Share this post


Link to post
Share on other sites

Okay thanks guys. I'll play around with this stuff.

Share this post


Link to post
Share on other sites

Don't bother with UnitCapture/UnitPlay - that's just for playback of recorded movement, and wouldn't be useful in this situation (though it is very handy in others).

Here is Morieza's script converted to .sqf for Arma 2. I'm pretty sure I got it right, as Squint likes it and it seems to work in-game.

Don't forget to name your helicopter and change the script call accordingly.

Again, all respect and glory to Morieza.

flysafe.sqf:

// add to unit init:  
//nul = [HeliName,100,0.1] execVM "flysafe.sqf";
//change "HeliName" to name of unit, change "100" to whatever altitude you prefer

private ["_fus","_fhz","_fhu","_fhtg","_fhs","_fudz","_fhdz","_dfu","_ftx","_fty","_fu","_fhd","_fdy","_fhtr","_dy"];
_fu = _this select 0;
_fhd = _this select 1;
_fdy = _this select 2;

_fhtr = "Helihempty" createVehicle (position _fu);
_fus = getPos _fu select 2;
_dy = _fdy * 0.5;

while {alive _fu} do {

if (speed _fu > 1) then {
	_fus = speed _fu;
	_fhz = getPos _fu select 2;
	_fhu = getPosASL _fu select 2;
	_fhtg = getPosASL _fhtr select 2;
};

if (_fhd > _fhz) then {
	_fhs = _fhz + _fus; 
	_fudz = -_fus * _fus; 
	_fhdz = _fhd + ((_fhd - _fhz) * 2);
};

if (_fhd < _fhz) then {
	_fhs = _fhd + _fus; 
	_fudz = _fhz * 0.1; 
	_fhdz = (_fhz + (_fhd * 0.05)) - ((_fhz - _fhd) * 0.1);
};

_dfu = getDir _fu;
_ftx = _fhs *sin(_dfu);
_fty = _fhs *cos(_dfu);
_fhtr setPos [(getPos _fu select 0) + _ftx, (getPos _fu select 1) + _fty];

if (_fhtg + (_fhd * 0.5) > _fhu) then {
	_fu flyInHeight ((_fhtg + (_fhd * 0.5)) - _fhu) + (_fhd * 1.2); 
	_fu limitSpeed _fudz;
}

else {

	_fu flyInHeight _fhdz; 
	if (_fhd * 0.6 > _fhz) then {
		_fu limitSpeed _fudz;
	} 

	else {

	_fu limitSpeed _fus * (1 + ((_fhu - _fhtg) * 0.002));
	};
};

sleep _dy;
};

deleteVehicle _fhtr;

Share this post


Link to post
Share on other sites

Okay I don't know why but the script makes it so much worse. The helicopter keeps trying to land and it crashes.

Share this post


Link to post
Share on other sites

How are you setting up your helicopter overwatch - just cycled waypoints? A lot more information is needed here.

Share this post


Link to post
Share on other sites

@CMajor28: please try this, (if you still interest to use that script)

add this define part above "while {alive _fu} do {" line:

_fhs = _fhd + _fus;
_fudz = _fus;
_fhdz = _fus;

find this part in the script:

if (_fhd > _fhz) then {

change to:

if (_fhd > _fhz and "MOVE" == currentCommand _fu) then {

...please feel free to optimize, tweak or expand the script.

@Harzach: thanks for converting the script to sqf, it works.

Share this post


Link to post
Share on other sites

No problem, thanks for sharing!

I did find that higher altitude settings resulted in smoother flight overall, while altitudes lower than 50m or so resulted in the heli dragging ass up the sides of steep hills (not actually impacting terrain, just very slowly climbing up over it).

I'm not sure what the additional code changes - I haven't even analyzed the original code to see what it is really doing - but it seems a little bit smoother/more natural now.

Amended code:

private ["_fus","_fhz","_fhu","_fhtg","_fhs","_fudz","_fhdz","_dfu","_ftx","_fty","_fu","_fhd","_fdy","_fhtr","_dy"];
_fu = _this select 0;
_fhd = _this select 1;
_fdy = _this select 2;

_fhtr = "Helihempty" createVehicle (position _fu);
_fus = getPos _fu select 2;
_dy = _fdy * 0.5;

_fhs = _fhd + _fus;
_fudz = _fus;
_fhdz = _fus; 

while {alive _fu} do {

   if (speed _fu > 1) then {
       _fus = speed _fu;
       _fhz = getPos _fu select 2;
       _fhu = getPosASL _fu select 2;
       _fhtg = getPosASL _fhtr select 2;
   };

   if (_fhd > _fhz and "MOVE" == currentCommand _fu) then {  
       _fhs = _fhz + _fus; 
       _fudz = -_fus * _fus; 
       _fhdz = _fhd + ((_fhd - _fhz) * 2);
   };

   if (_fhd < _fhz) then {
       _fhs = _fhd + _fus; 
       _fudz = _fhz * 0.1; 
       _fhdz = (_fhz + (_fhd * 0.05)) - ((_fhz - _fhd) * 0.1);
   };

   _dfu = getDir _fu;
   _ftx = _fhs *sin(_dfu);
   _fty = _fhs *cos(_dfu);
   _fhtr setPos [(getPos _fu select 0) + _ftx, (getPos _fu select 1) + _fty];

   if (_fhtg + (_fhd * 0.5) > _fhu) then {
       _fu flyInHeight ((_fhtg + (_fhd * 0.5)) - _fhu) + (_fhd * 1.2); 
       _fu limitSpeed _fudz;
   }

   else {

       _fu flyInHeight _fhdz; 
       if (_fhd * 0.6 > _fhz) then {
           _fu limitSpeed _fudz;
       } 

       else {

       _fu limitSpeed _fus * (1 + ((_fhu - _fhtg) * 0.002));
       };
   };

   sleep _dy;
};

deleteVehicle _fhtr;

Share this post


Link to post
Share on other sites

Okay thanks guys. I'll try this when I have a chance. And it was a seek and destroy waypoint.

EDIT: I keep trying this script and I can't get it to work. It doesn't help at all. It may have something to do with the seek and destroy waypoint.

Edited by CMajor28

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  

×