Jump to content
darrent

ai heli making a combat landing

Recommended Posts

my plan was to have a huey  make a combat landing as in vietnam, as we all know the ai  are not up to it, so i attempted the unit capture/play route, no luck there could never get the script to work.so is there any other way to make the huey make a combat landing?

Share this post


Link to post
Share on other sites

 

To make heli land and unload you can do two things , in script:


 

// First create the landing position

private _lz = "Land_HelipadEmpty_F" createVehicle _lzpos;


// Add landing waypoint for heli group

_wp = _heloGrp addwaypoint [_lzpos,0];
_wp setWaypointType "TR UNLOAD";

 

Those codes wont work without modifying for your heli setup. But that's how you do it.

 

 

 

EDIT: Or in editor place invisible helipad and add Transport unload waypoint on top of that. should work

 

 

Share this post


Link to post
Share on other sites

but does that still make the heli do a lazy slow landing ? getting them to land is not a problem  ,they just take so damn long to land. been away from the game for a few yrs,forgotten loads of it.wondered if any 1 had cracked the secret of quick landings yet

 

Share this post


Link to post
Share on other sites
4 minutes ago, darrent said:

but does that still make the heli do a lazy slow landing ? getting them to land is not a problem  ,they just take so damn long to land. been away from the game for a few yrs,forgotten loads of it.wondered if any 1 had cracked the secret of quick landings yet

 

 

Yes it's quite slow landing compared to real combat landings

Share this post


Link to post
Share on other sites

so no ones cracked the code for quick ai landings yet then  😞   i had hoped the unitcapture/unitplay would solve it, but 7 hrs in and it still wont work.. slow landings it is then

 

Share this post


Link to post
Share on other sites

If not enough, use brute force. I'm doing so in Hermes Airlift Services script using this function:

 

RYD_HAS_AutoGuideB = 
	{
	if (RYD_TI_ControlTI) exitWith {};
	
	params ["_heli","_lvl","_var","_refPos","_tol","_vMpl","_frc"];
		
	private _vel = velocity RYD_HAS_Chopper;
	private _lvl2 = (getPos RYD_HAS_Chopper) select 2;

	private _vel0 = random ((random (2 * _var)) - _var);
	private _vel1 = random ((random (2 * _var)) - _var);
	private _vel2 = random ((random (2 * _var)) - _var);
	
	private _dst = _heli distance2D _refPos;
	
	if (_dst > _tol) then
		{
		private _vect = (position _heli) vectorFromTo _refPos;
		private _spd = ((_dst - 1) max 1) min 10;
		_vel0 = _vel0 + ((_vect select 0) * _spd * _vMpl);
		_vel1 = _vel1 + ((_vect select 1) * _spd * _vMpl);
		};
		
	_heli setVelocity [((_vel select 0) * _frc) + (_vel0 * (1 - _frc)),((_vel select 1) * _frc) + (_vel1 * (1 - _frc)),((_vel select 2) * _frc) + ((_vel2 + ((((_lvl - _lvl2) max (-(_lvl2 * 0.5) max (-2 min -((_lvl2^0.6)/3)))) min (((_vel select 2) max 0) * 1.1)) * _vMpl)) * (1 - _frc))]	
	};

 

Not 100% realistic in terms of aerodynamics, but IMO tolerable. Example call:

 

[RYD_HAS_Chopper,0.5,0,RYD_HAS_clickedPos,2,3,_frc] call RYD_HAS_AutoGuideB;

 

RYD_HAS_Chopper - your chopper.

0.5 - target altitude

0 - some randomness factor

RYD_HAS_clickedPos - a position to touch down at

2 - miss spot tolerance (if above this number of meters, will adjust horizontal positioning along with altitude

3 - descent velocity multiplier

_frc - a number between 0 and 1 - how fast current velocity is turned into target descent velocity (smoothness). 

 

It should be called constantly (say in the waitUntil loop with 0.1 sleep or maybe even per frame, although that may be too fast) till heli is and as long should stay "landed". Example from HAS context (no for standalone usage!):

 

			_frc = 0.9;
			waitUntil 
				{
				sleep 0.1;
				_alive = (alive RYD_HAS_Chopper) and {(canMove RYD_HAS_Chopper)};
				
				if not (_alive) exitWith {true};
				if not ([] call RYD_HAS_ifChopperReady) exitWith {_unable = true;true};
				
				if (RYD_HAS_FastRoping) then
					{
					[RYD_HAS_Chopper,_minLvl,0,RYD_HAS_clickedPos,2,1] call RYD_HAS_AutoGuide;
					}
				else
					{
					[RYD_HAS_Chopper,0.5,0,RYD_HAS_clickedPos,2,3,_frc] call RYD_HAS_AutoGuideB;
					_frc = (_frc - 0.025) max 0;
					};
				
				((((getPos RYD_HAS_Chopper) select 2) < (_minLvl * 1.1)) and {((RYD_HAS_Chopper distance2D RYD_HAS_clickedPos) < 4)})
				};

 

 

 

  • Like 4

Share this post


Link to post
Share on other sites

I once wrote a script that made heli land quick and accurate but I had problems getting the player camera working as it would jitter around. @Rydygier did you have any problems with camera?

Share this post


Link to post
Share on other sites

I didn't noticed such issues so far. 

Share this post


Link to post
Share on other sites
Just now, Rydygier said:

I didn't noticed such issues so far. 

 

oh ok that's good to hear. had to ditch my script because of that 

Share this post


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

my plan was to have a huey  make a combat landing as in vietnam, as we all know the ai  are not up to it, so i attempted the unit capture/play route, no luck there could never get the script to work.so is there any other way to make the huey make a combat landing?

 

Go onto Youtube, and watch some of the videos of how to use the unit capture/unit play function. 

  • Like 1

Share this post


Link to post
Share on other sites

been there done that 7hrs later no dice, just will not work, followed to the letter

Share this post


Link to post
Share on other sites

@Rydygier can your script be activaded in trigger so the heli make a quick landing, i want to use it for a intro to my sp mission.

 

Cheers play3r

 

RYD_HAS_AutoGuideB = { if (RYD_TI_ControlTI) exitWith {}; params ["_heli","_lvl","_var","_refPos","_tol","_vMpl","_frc"]; private _vel = velocity RYD_HAS_Chopper; private _lvl2 = (getPos RYD_HAS_Chopper) select 2; private _vel0 = random ((random (2 * _var)) - _var); private _vel1 = random ((random (2 * _var)) - _var); private _vel2 = random ((random (2 * _var)) - _var); private _dst = _heli distance2D _refPos; if (_dst > _tol) then { private _vect = (position _heli) vectorFromTo _refPos; private _spd = ((_dst - 1) max 1) min 10; _vel0 = _vel0 + ((_vect select 0) * _spd * _vMpl); _vel1 = _vel1 + ((_vect select 1) * _spd * _vMpl); }; _heli setVelocity [((_vel select 0) * _frc) + (_vel0 * (1 - _frc)),((_vel select 1) * _frc) + (_vel1 * (1 - _frc)),((_vel select 2) * _frc) + ((_vel2 + ((((_lvl - _lvl2) max (-(_lvl2 * 0.5) max (-2 min -((_lvl2^0.6)/3)))) min (((_vel select 2) max 0) * 1.1)) * _vMpl)) * (1 - _frc))] };

 

Not 100% realistic in terms of aerodynamics, but IMO tolerable. Example call:

 

[RYD_HAS_Chopper,0.5,0,RYD_HAS_clickedPos,2,3,_frc] call RYD_HAS_AutoGuideB;

 

RYD_HAS_Chopper - your chopper.

0.5 - target altitude

0 - some randomness factor

RYD_HAS_clickedPos - a position to touch down at

2 - miss spot tolerance (if above this number of meters, will adjust horizontal positioning along with altitude

3 - descent velocity multiplier

_frc - a number between 0 and 1 - how fast current velocity is turned into target descent velocity (smoothness). 

 

It should be called constantly (say in the waitUntil loop with 0.1 sleep or maybe even per frame, although that may be too fast) till heli is and as long should stay "landed". Example from HAS context (no for standalone usage!):

 

_frc = 0.9; waitUntil { sleep 0.1; _alive = (alive RYD_HAS_Chopper) and {(canMove RYD_HAS_Chopper)}; if not (_alive) exitWith {true}; if not ([] call RYD_HAS_ifChopperReady) exitWith {_unable = true;true}; if (RYD_HAS_FastRoping) then { [RYD_HAS_Chopper,_minLvl,0,RYD_HAS_clickedPos,2,1] call RYD_HAS_AutoGuide; } else { [RYD_HAS_Chopper,0.5,0,RYD_HAS_clickedPos,2,3,_frc] call RYD_HAS_AutoGuideB;  _frc = (_frc - 0.025) max 0; }; ((((getPos RYD_HAS_Chopper) select 2) < (_minLvl * 1.1)) and {((RYD_HAS_Chopper distance2D RYD_HAS_clickedPos) < 4)}) };

 

Share this post


Link to post
Share on other sites

After few adaptations. You still need to put some stuff into eg init.sqf:

 

RYD_AutoGuideB = 
	{	
	params ["_heli","_lvl","_var","_refPos","_tol","_vMpl","_frc"];
		
	private _vel = velocity _heli;
	private _lvl2 = (getPos _heli) select 2;

	private _vel0 = random ((random (2 * _var)) - _var);
	private _vel1 = random ((random (2 * _var)) - _var);
	private _vel2 = random ((random (2 * _var)) - _var);
	
	private _dst = _heli distance2D _refPos;
	
	if (_dst > _tol) then
		{
		private _vect = (position _heli) vectorFromTo _refPos;
		private _spd = ((_dst - 1) max 1) min 10;
		_vel0 = _vel0 + ((_vect select 0) * _spd * _vMpl);
		_vel1 = _vel1 + ((_vect select 1) * _spd * _vMpl);
		};
		
	_heli setVelocity [((_vel select 0) * _frc) + (_vel0 * (1 - _frc)),((_vel select 1) * _frc) + (_vel1 * (1 - _frc)),((_vel select 2) * _frc) + ((_vel2 + ((((_lvl - _lvl2) max (-(_lvl2 * 0.5) max (-2 min -((_lvl2^0.6)/3)))) min (((_vel select 2) max 0) * 1.1)) * _vMpl)) * (1 - _frc))]	
	};
	
RYD_FastLand = 
	{
	params ["_heli","_pos","_minLvl","_mpl"];

	RYD_TouchDown = true;
	
	_frc = 0.9;
	waitUntil 
		{
		sleep 0.02;
		_alive = not (isNull _heli) and {(alive _heli) and {(canMove _heli)}};		
		if not (_alive) exitWith {true};
		
		_cP = currentPilot _heli;
		_alive = not (isNull _cP) and {(alive _cP)};		
		if not (_alive) exitWith {true};

		[_heli,_minLvl/2,0,_pos,2,_mpl,_frc] call RYD_AutoGuideB;
		_frc = (_frc - 0.025) max 0;
		
		(not RYD_TouchDown)
		};
		
	hint "Off we go!";
	};
	
RYD_TouchDown = false;

 

Then you can control combat landings via triggers, that would execute RYD_FastLand and manipulate RYD_TouchDown to switch the procedure on/off.

 

And whole setup with two triggers activated via radio channels:

Fast touch down demo

 

Here it is set really fast (5) to make more prominent, what it is about:

TDHandle = [heli1,(player modelToWorld [0,20,0]),0.5,5] spawn RYD_FastLand;

[your heli name, landing pos, hovering altitude (will be a bit lower in fact),descent speed multiplier]

 

It looks like this:

 

Share this post


Link to post
Share on other sites

Thanks @Rydygier

All I want is a fast landing when player is flying in to the Mission area at the start of the game, so my plan was to make the heli make a fast handing and then shut off engine, I was thinking about putting it inside ACT in trigger so when the heli comes inside it starts to decent and land, at the marker that is placed on map.

 

The pilot is ai but in players group, but I guess it doesn't matter.

Share this post


Link to post
Share on other sites

Well, that's a bit more tricky, because in that case you need to "glue together" scripted enforced descent with native AI landing behavior. You can get this by changing RYD_FastLand this way:

 

RYD_FastLand = 
	{
	params ["_heli","_pos","_minLvl","_mpl"];
	_frc = 0.9;
	waitUntil 
		{
		sleep 0.02;
		_alive = not (isNull _heli) and {(alive _heli) and {(canMove _heli)}};		
		if not (_alive) exitWith {true};
		
		_cP = currentPilot _heli;
		_alive = not (isNull _cP) and {(alive _cP)};		
		if not (_alive) exitWith {true};

		[_heli,_minLvl/2,0,_pos,2,_mpl,_frc] call RYD_AutoGuideB;
		_frc = (_frc - 0.025) max 0;
		
		((((getPos _heli) select 2) < ((_minLvl * 1.1) max 0.2)) and {((_heli distance2D _pos) < 4)})
		};
	
	_lz = createVehicle ["Land_HelipadEmpty_F", _pos, [], 0, "CAN_COLLIDE"];//optional line
	_heli land "LAND";
	};

 

Set condition of the first trigger to "this" and remove second trigger.

 

But part of native landing procedure is small "jump" at the begining, which kinda spoils the effect.

 

An alternative would be faking via script whole thing by setting hovering altitude to 0 and doing this instead of above:

 

RYD_FastLand = 
	{
	params ["_heli","_pos","_minLvl","_mpl"];
	_frc = 0.9;
	waitUntil 
		{
		sleep 0.02;
		_alive = not (isNull _heli) and {(alive _heli) and {(canMove _heli)}};		
		if not (_alive) exitWith {true};
		
		_cP = currentPilot _heli;
		_alive = not (isNull _cP) and {(alive _cP)};		
		if not (_alive) exitWith {true};

		[_heli,_minLvl/2,0,_pos,2,_mpl,_frc] call RYD_AutoGuideB;
		_frc = (_frc - 0.025) max 0;
		
		if ((isEngineOn _heli) and {(((getPos _heli) select 2) < ((_minLvl * 1.1) max 0.2))}) then
			{
			deleteWaypoint [(group _heli),(currentWaypoint (group _heli))];
			_heli doMove _pos;
			_heli engineOn false;
			};
			
		not (player in _heli)
		};

 

In this case the loop, that presses the heli to the ground stops, when player exits the heli and the engine is turned off by this script when heli reaches the ground. Like this.

 

Share this post


Link to post
Share on other sites

@Rydygier

 

This is great, i have just tried the mission from DB and it look awesome, Thanks for your time.

The COND that the heli have to be within 120 Mtr from the marker is something i had not thought could be a solution.     

i would just had made a trigger and had the heli fly thru it to activate the trigger, that is now put in my small script page.

 

Cheers Play3r 

 

@Rydygier

After i have played around with your script i found out that if i just make a heli with AI only they don't land on the marker only if i play as one of the Ai it will land any chance i can change something so i can have two helis land in my intro ??

 

Found the solution just had to change this 

not (player in _heli)

To this

! not (player in _heli)

Then  heli1 with only  AI in it will land on the marker.

 

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

×