Jump to content
BEAKSBY

Helpful Tips to get to get my plane to fly reliably to its waypoints

Recommended Posts

Hi ALL,

My plane doesn't always make it to it's target to drop it's cargo, sometimes it vears off and crashes enroute?

Anyone have some helpful tips to ensure it flies to it's waypoints 100% of the time without crashing?

I've been experimenting with distances, altitudes and speeds but none seem reliable enought to guarantee 100% success?

//if (isServer)exitWith{};
private ["_mp","_grp","_planeType","_men","_grp2","_center","_man1","_man2","_landingSpot","_side","_flyHeight","_openHeight","_jumpDelay","_jumperAmount","_planeDistance","_planeDirection","_flyBy","_allowDamage","_BLUmen","_OPFmen","_INDmen","_BLUplane","_OPFplane","_INDplane","_landingSpotPos","_spos","_plane","_crew","_dir","_flySpot","_jumpDistanceFromTarget","_captive","_smokes","_flares","_chems","_skls","_cPosition","_cRadius","_patrol","_target","_cycle","_skills","_customInit","_grpId","_wp0","_wp1","_doorHandling"];

_landingSpotPos = _this select 0;
_vehDir = _this select 1;
_vehType = _this select 2;
_AI = _this select 3;
_randomMarkerDestination = _this select 4;

_allowDamage = FALSE;
_captive = TRUE;
_planeDistance = 2000;
_flyBy = TRUE;
_flyHeight = 500;
_jumpDistanceFromTarget = 25;
_speed = 600 / 3.6;  // (converted from km/hr to m/s))
_planeDirection = floor(random 360);

//Drop smoke & Chem light & Flare
_smoke = createVehicle ["SmokeShellGreen",[(_landingSpotPos select 0), (_landingSpotPos select 1), 0],[], 0, "NONE"];
_chemlight = createVehicle ["Chemlight_green",[(_landingSpotPos select 0), (_landingSpotPos select 1), 0],[], 0, "NONE"]; 
_flarePos = [(_landingSpotPos select 0), (_landingSpotPos select 1), 125];
_flare = createVehicle [ "F_20mm_green", _flarePos, [], 0, "FLY" ]; 
_flare setVelocity [ 0, 0, -1 ];  

//Classnames:
_BLUplane = "C130J_Cargo";

//Side related group creation:
switch(side player)do{
	case WEST:{
		_center = createCenter east;
		_grp = createGroup east;
		_planeType = _BLUplane;
	};
	case EAST:{
		_center = createCenter west;
		_grp = createGroup west;
		_planeType = _BLUplane;
	};
};

//Spawn plane
_spos = [(_landingSpotPos select 0) - (sin _planeDirection) * _planeDistance, (_landingSpotPos select 1) - (cos _planeDirection) * _planeDistance, 500];
_plane = createVehicle [_planeType, _spos, [], 0, "NONE"];
_vel = velocity _plane;
_plane setDir _planeDirection;

//Count angle between plane and target, and end spot for plane
_vectorDir = [_spos,_landingSpotPos] call bis_fnc_vectorFromXtoY;
_plane setVelocity (_vectorDir vectorMultiply _speed);
_plane allowDamage _allowDamage;

// MAY HAVE TO REMOVE CREW FIRST
_crew = crew _plane;
{deletevehicle _x} foreach _crew;
_crew = [_plane,_grp] call bis_fnc_spawncrew;
if(_captive)then{_plane setCaptive true;
{ _x setCaptive true; } forEach units _grp;
};

_flySpot = [(_landingSpotPos select 0) + (sin _planeDirection) * _planeDistance, (_landingSpotPos select 1) + (cos _planeDirection) * _planeDistance, 500];


//plane to go
if(_flyBy)then{
_wp0 = _grp addWaypoint [_landingSpotPos, 0, 1];
[_grp,0] setWaypointBehaviour "CARELESS";
[_grp,0] setWaypointCompletionRadius 50;
[_grp,0] setWaypointSpeed "FULL";
// _grp SetUnitPos "Up";

_wp1 = _grp addWaypoint [_flySpot, 0, 2];
[_grp,1] setWaypointBehaviour "CARELESS";
[_grp,1] setWaypointCompletionRadius 50;
[_grp,1] setWaypointSpeed "FULL";
// _grp SetUnitPos "Up";
};

_plane flyInHeight _flyHeight;

//Wait until plane is close enough
waitUntil{([_plane, _landingSpotPos] call BIS_fnc_distance2D) < _jumpDistanceFromTarget};
_planeAlt = (getPosASL _plane) select 2;

//_plane disableCollisionWith _vehType;


//_plane flyInHeight _flyHeight;
//waitUntil{([_plane, _landingSpotPos] call BIS_fnc_distance2D) > 1000};
sleep 15;
//--- Delete plane
   _group = group _plane;
   deletevehicle _plane;
   {deletevehicle _x} foreach crew _plane;
   deletegroup _group;
//hint "DELETE PLANE";
   // Delete smoke and light
sleep 10;
   deleteVehicle _smoke;
   deleteVehicle _chemlight;
   deleteVehicle _flare;

Share this post


Link to post
Share on other sites

The only thing that works 100% solid is to fly the plane yourself and record it:

https://community.bistudio.com/wiki/BIS_fnc_UnitCapture

(tutorial links at bottom of page)

And to play back for the mission https://community.bistudio.com/wiki/BIS_fnc_UnitPlay

The next best thing is to do things like setBehavior "SAFE" or "CARELESS" https://community.bistudio.com/wiki/setBehaviour

Some of the disableAI commands (target, autotarget, maybe fsm): https://community.bistudio.com/wiki/disableAI

setCombatMode "BLUE" https://community.bistudio.com/wiki/setCombatMode

But again, I've seen certain AI mods override these which is very annoying to say the least.

Share this post


Link to post
Share on other sites
The only thing that works 100% solid is to fly the plane yourself and record it:

https://community.bistudio.com/wiki/BIS_fnc_UnitCapture

(tutorial links at bottom of page)

And to play back for the mission https://community.bistudio.com/wiki/BIS_fnc_UnitPlay[...]

That won't for in this case so far I unstand. His location is somewhat random.

Share this post


Link to post
Share on other sites

I've tried replacing "NONE" with "FLY" in:

_plane = createVehicle [_planeType, _spos, [], 0, "NONE"];

And it had no effect for improving the flight behaviour to the waypoints, why?

Share this post


Link to post
Share on other sites
I've tried replacing "NONE" with "FLY" in:

_plane = createVehicle [_planeType, _spos, [], 0, "NONE"];

And it had no effect for improving the flight behaviour to the waypoints, why?

"FLY" only means that it spawns flying. You could also set it to spawn in formation etc.

Share this post


Link to post
Share on other sites

Hi BEAKSBY not seen you for a while.

I assume your placing a pilot in the plane, have you tried dumbing him down a bit?

pilotname disableAI "target";pilotname disableAI "autotarget";pilotname disableAI "FSM;

also if it's stalling on creation you may need to add some velocity

_plane setVelocity [100 * (sin (getdir _plane)), 100 * (cos (getdir _plane )), 1];

Don't place waypoints to close together as they may be struggling to reach them given the limited turning radius (about 500m min distance between WP) and try increasing completion radius.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Thanks F2k Sel,

1) I've tried a number of things and found that the speed is initially to 600km/hr according to either:

_plane setVelocity (_vectorDir vectorMultiply _speed);

OR

_plane setVelocity [_speed * (sin (getdir _plane)), _speed * (cos (getdir _plane )), 1];

but then the speed drops back to 0 after a second and then starts ramping up again as the plane dives down?

2) Also, I notice that it is not flying at the altitude of the waypoints I set in "addwapoint", it seems to want to remain at around 94m from the ground?

AIcargoPlane.sqf

//if (isServer)exitWith{};
private ["_landingSpotPos","_vehDir","_vehType","_AI","_randomMarkerDestination","_allowDamage","_captive","_planeDistance","_flyBy","_flyHeight","_jumpDistanceFromTarget",
"_speed","_planeDirection","_alt","_data","_smoke","_chemlight","_flarePos","_flare","_BLUplane","_grp","_planeType","_planePos","_planeArray","_plane","_vel",
"_vectorUp","_plane","_crew","_dir","_targetDrop","_exitSpot","_script","_planeAlt","_group","_wp0","_wp1"];

_landingSpotPos = _this select 0;
_vehDir = _this select 1;
_vehType = _this select 2;
_AI = _this select 3;
_randomMarkerDestination = _this select 4;

_allowDamage = TRUE;
_captive = TRUE;
_planeDistance = 2000;
_flyBy = TRUE;
_flyHeight = 500;
_jumpDistanceFromTarget = 25;
_speed = 600 / 3.6;  // (converted from km/hr to m/s))
_planeDirection = floor(random 360);
_alt = 1000;
_data = [];

//Drop smoke & Chem light & Flare
_smoke = createVehicle ["SmokeShellGreen",[(_landingSpotPos select 0), (_landingSpotPos select 1), 0],[], 0, "NONE"];
_chemlight = createVehicle ["Chemlight_green",[(_landingSpotPos select 0), (_landingSpotPos select 1), 0],[], 0, "NONE"]; 
_flarePos = [(_landingSpotPos select 0), (_landingSpotPos select 1), 125];
_flare = createVehicle [ "F_20mm_green", _flarePos, [], 0, "FLY" ]; 
_flare setVelocity [ 0, 0, -1 ];  

//Classnames:
_BLUplane = "C130J_Cargo";

//Side related group creation:
switch(side player)do{
	case WEST:{
		_center = createCenter east;
		_grp = createGroup east;
		_planeType = _BLUplane;
	};
	case EAST:{
		_center = createCenter west;
		_grp = createGroup west;
		_planeType = _BLUplane;
	};
};

//Spawn plane
_planePos = [(_landingSpotPos select 0) - (sin _planeDirection) * _planeDistance, (_landingSpotPos select 1) - (cos _planeDirection) * _planeDistance, _alt];
_planePos set [2,(_planePos select 2) + getTerrainHeightASL _planePos];
//_plane = createVehicle [_planeType, _planePos, [], 0, "FLY"];
_planeArray = [_planePos,_planeDirection,_planeType, _grp] call BIS_fnc_spawnVehicle;
_plane = _planeArray select 0;
_vel = velocity _plane;
_plane setPos _planePos;
_plane setDir _planeDirection;

//Count angle between plane and target, and end spot for plane
_vectorDir = [_planePos,_landingSpotPos] call bis_fnc_vectorFromXtoY;
//_plane setVelocity (_vectorDir vectorMultiply _speed);
//_plane setVelocity [_speed * (sin (getdir _plane)), _speed * (cos (getdir _plane )), 1]; 
_plane allowDamage _allowDamage;

[_plane,-90 + atan (_planeDistance / _alt),0] call bis_fnc_setpitchbank;
//_velocity = [_vectorDir,_speed] call bis_fnc_vectorMultiply;
//_plane setVelocity _velocity;
_plane setVelocity (_vectorDir vectorMultiply _speed);
_plane setvectordir _vectorDir;
_vectorUp = vectorup _plane;

// MAY HAVE TO REMOVE CREW FIRST
//_crew = crew _plane;
//{deletevehicle _x} foreach _crew;
//_crew = [_plane,_grp] call bis_fnc_spawncrew;

if(_captive)then{_plane setCaptive true;
{ 
	_x setCaptive true; 
	//_x disableAI "MOVE";
	_x disableAI "TARGET";
	_x disableAI "AUTOTARGET";
	_x disableAI "FSM";
} forEach units _grp;
};

//Waypoints
_targetDrop = [_landingSpotPos select 0, _landingSpotPos select 1, _flyHeight];
_exitSpot = [(_landingSpotPos select 0) + (sin _planeDirection) * _planeDistance, (_landingSpotPos select 1) + (cos _planeDirection) * _planeDistance, _alt];
if(_flyBy)then{
_wp0 = _grp addWaypoint [_targetDrop, 0];
_wp0 setWaypointType "MOVE";
[_grp,0] setWaypointBehaviour "CARELESS";
[_grp,0] setWaypointCompletionRadius 25;
[_grp,0] setWaypointSpeed "FULL";
// _grp SetUnitPos "Up";

_wp1 = _grp addWaypoint [_exitSpot, 0];
_wp1 setWaypointType "MOVE";
[_grp,1] setWaypointBehaviour "CARELESS";
[_grp,1] setWaypointCompletionRadius 25;
[_grp,1] setWaypointSpeed "FULL";
// _grp SetUnitPos "Up";
};

_script = [_plane, _landingSpotPos, _jumpDistanceFromTarget] spawn {
for "_i" from 0 to 100 do {
	_plane = _this select 0;
	_landingSpotPos = _this select 1;
	_jumpDistanceFromTarget = _this select 2;
	_distance2D = [_plane, _landingSpotPos] call BIS_fnc_distance2D;
	hint format ["distance2D: %1 \n _speed: %2 \n direction: %3 \n _plane: %4 \n _alt: %5 \n <25m?: %6",
	round _distance2D, round speed _plane, round getdir _plane, _plane, 
	round((getPosASL _plane) select 2),(([_plane, _landingSpotPos] call BIS_fnc_distance2D) < _jumpDistanceFromTarget) ];
	sleep .5;
	/*
	diag_log format ["distance2D: %1 \n _speed: %2 \n direction: %3 \n _plane: %4 \n _alt: %5 \n <25m?: %6",
	round _distance2D, round speed _plane, round getdir _plane, _plane, 
	(getPosASL _plane) select 2,(([_plane, _landingSpotPos] call BIS_fnc_distance2D) < _jumpDistanceFromTarget)];
	*/
	};
};

//Wait until plane is close enough for Drop
waitUntil{(([_plane, _landingSpotPos] call BIS_fnc_distance2D) < _jumpDistanceFromTarget)};
//hint "HELLO PLANE AFTER";
//hint format ["_vehType: %1 \n _landingSpotPos: %2 \n distance2D: %3 \n distance2D < _jumpDistanceFromTarget: %4", _vehType,  _landingSpotPos, ([_plane, _landingSpotPos] call BIS_fnc_distance2D), ([_plane, _landingSpotPos] call BIS_fnc_distance2D) < _jumpDistanceFromTarget ];
_planeAlt = (getPosASL _plane) select 2;

//_plane disableCollisionWith _vehType;

switch (true) do { 
case   ((_vehType iskindof "car") or (_vehType iskindof "tank") and !(((_vehType == "B_MBT_01_arty_F") or (_vehType == "O_MBT_02_arty_F")))) : {[_vehType, _landingSpotPos, _plane, _AI, _randomMarkerDestination] spawn BEAKS_fnc_AIVehicleDrop, deleteWaypoint [_grp,0], deleteWaypoint [_grp,1];};
case   (_vehType iskindof "StaticWeapon") : {[_vehType, _planeDirection, _landingSpotPos, _plane] spawn BEAKS_fnc_StaticWeaponDrop, deleteWaypoint [_grp,0], deleteWaypoint [_grp,1];};
case   (_vehType iskindof "Man") : 	{[_vehType, _planeDirection, _landingSpotPos, _plane] spawn BEAKS_fnc_ManDrop, deleteWaypoint [_grp,0], deleteWaypoint [_grp,1];};
}: 

//_plane flyInHeight _flyHeight;

//waitUntil{([_plane, _landingSpotPos] call BIS_fnc_distance2D) > 1000};  // OR
sleep 15;
//--- Delete plane
   _group = group _plane;
   deletevehicle _plane;
   {deletevehicle _x} foreach crew _plane;
   deletegroup _group;
//hint "DELETE PLANE";
   // Delete smoke and light
sleep 10;
   deleteVehicle _smoke;
   deleteVehicle _chemlight;
   deleteVehicle _flare;		

Share this post


Link to post
Share on other sites

I'm not sure, sounds like the AI is not in the plane.

I did force an AI into another plane as I don't have the C130 and it didn't crash but for the life of me I couldn't get it to fly at a given altitude.

Share this post


Link to post
Share on other sites

I'm not sure, sounds like the AI is not in the plane.

I did force an AI into another plane as I don't have the C130 and it didn't crash but for the life of me I couldn't get it to fly at a given altitude.

I'm pretty sure you know about this; worth a shot tho if it helps..

_veh flyinHeight 30;

Share this post


Link to post
Share on other sites

NM, I can post a new thread now :-) Sorry about the attempted Hijack

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

×