Jump to content
Sign in to follow this  
ylguf

[script] apply wind to Helicopters

Recommended Posts

CURRENT HELI EFFECTS:

wind

up/down drafts near slopes

settling with power/ vortex ring

autorotation

here is a link to download the version with a hud for altimeter and angle of decent

https://drive.google.com/folderview?id=0B9h9R7CKifzDOUZjNkYxYWVkd1k&usp=sharing

-------------------------------------------------------------------------------------------------------------------------

if you decend faster then 7m/s and have a angle of decent thatS greater then 30 you will start settling with power.

this translates to keeping your airspeed above 60 or decending slowly.(look up height velocity diagrams)

also you can autorotate out of settling with power.

-------------------------------------------------------------------------------------------------------------------------

videos

I removed the hint and added turbulence so these 2 are outdated(also released a hud)

-------------------------------------------------------------------------------------------------------------------------

place the following code in .sqf's in the mission file

init.sqf

execVM "helieffects.sqf";

helieffects.sqf

while {true} do
{
waitUntil{vehicle player isKindOf "Air" && (driver vehicle player == player)};
_unit = vehicle player;
enableCamShake true;
//to change the wind:
//10-20 seems to work good, lower _windstrength number to make wind stronger, warning if the wind is to strong you might have trouble flying in certain circumstances.
_windstrength = 15;

while{driver _unit == player && (!(isTouchingGround (_unit))) && ((getPosATL(_unit) select 2) > 1) }do
{
	_starttime = time;
/*----------------------WIND--------------------- */

	_unitvelocity = velocity _unit;
	_unitxv = _unitvelocity select 0;
	_unityv = _unitvelocity select 1;
	_unitzv = _unitvelocity select 2;
	_wind_unitvelocity = wind;
	_windxv = _wind_unitvelocity select 0;
	_windyv = _wind_unitvelocity select 1;
	_windzv = _wind_unitvelocity select 2;
	_unit setVelocity [(_unitXV + (_windXV/_windstrength)),(_unitYV + (_windYV/_windstrength)),(_unitZV + (_windZV/_windstrength))];

/*----------------------SETTLING WITH POWER / VOTEX RING EFFECT--------------------- */

	if(isEngineOn _unit)then
	{
		_unitvelocity = velocity _unit;
		_unitxv = _unitvelocity select 0;
		_unityv = _unitvelocity select 1;
		_unitzv = _unitvelocity select 2;
		_unitxyv = (sqrt((_unitxv ^ 2)+(_unityv ^ 2)));
		_unitxyzv = (sqrt((_unitxv ^ 2)+(_unityv ^ 2)+(_unitzv ^ 2)));
		if(_unitxyzv != 0)then
		{

			_unitAoD = (acos( _unitxyv / _unitxyzv));
			if((_unitzv <= -7.5) && (_unitAoD >= 31) && (_unitAoD <= 90))then
			{
				addCamShake [5, 0.5, 4];
				_unit setVelocity [(_unitxv),(_unityv),(_unitzv + (_unitzv/30) - 1.5)];
			};
		};
	};

/*----------------------UP/DOWN DRAFTS NEAR STEEP SLOPES--------------------- */

	 _height1 = getTerrainHeightASL (position _unit);
	sleep 0.1;
	_height2 = getTerrainHeightASL (position _unit);
	if((_height2 >= (_height1 + 1.2)) || (_height2 <= (_height1 - 1.2)))then
	{
		_unitvelocity = velocity _unit;
		_unitxv = _unitvelocity select 0;
		_unityv = _unitvelocity select 1;
		_unitzv = _unitvelocity select 2;
		_unit setVelocity [(_unitxv),(_unityv),(_unitzv + ((floor(random 3)) - 1))];
	};

/*----------------------AUTOROTATION--------------------- */

	if(!isEngineOn _unit)then
	{
		_unitvelocity = velocity _unit;
		_unitxv = _unitvelocity select 0;
		_unityv = _unitvelocity select 1;
		_unitzv = _unitvelocity select 2;
		_vectorup = vectorUp _unit;
		_unitxu = _vectorup select 0;
		_unityu = _vectorup select 1;
		_unitzu = _vectorup select 2;
		_velvec = (sqrt ( _unitxv ^ 2 + _unityv ^ 2 + _unitzv ^ 2 ));
		_div1 = ((_velvec)+sqrt(_unitxu^2+_unityu^2+_unitzu^2));
		_unitvelocityduxy = ((_unitxv*_unitxu + _unityv*_unityu + _unitzv*_unitzu)/_div1);
		_unitvelocityduz = (sin(acos _unitvelocityduxy));
		_deltatime = (time - _starttime);
		_zconv = (0.5 * _deltatime);
		_xyconv = (0.02 * _deltatime);
		_convvvar = (((-_unitvelocityduxy)*_zconv + (abs _unitvelocityduz)*_xyconv)*_velvec);
		_autowind = ((((_windxv/_windstrength) * _unitxu) + ((_windyv/_windstrength) * _unityu))*0.75);
		_unitxyzv = ([(_unitxv + _unitxu*_convvvar),(_unityv + _unityu*_convvvar),((_unitzv + _unitzu*_convvvar) + _autowind)]);
		_unit setVelocity _unitxyzv;
	};
};
};

-------------------------------------------------------------------------------------------------------------------------

updated: added wind to autorotation lift

updated: redid some mathamagics, added autorotation and hud(hud included in demo mission), rewrote code to be cleaner, demo mission link

updated: added camera shake to simulate turbulence

updated: added settling with power/vortex ring effects. still might need some number tweeks but it seems to work ok.

updated:cleaner code thanks to zooloo75

Edited by ylguf
update

Share this post


Link to post
Share on other sites

You could simplify your script completely by removing the first half of the if statements as they don't seem to be necessary since velocity values are signed; adding a negative will still subtract.

_unit setVelocity [(_unitXV + (_windXV/_div)),(_unitYV + (_windYV/_div)),(_unitZV + (_windZV/_div))];

So your script would look like this. (I also took the time to check if the vehicle is aerial as your script would apply to anything that is half a meter off the ground, that would cause problems for example, infantry on top of a building - causing them to fly away). Also the execVM line has extra information that isn't needed - you are passing the player to the script, but nowhere in the script is it being used.

player execVM "applywind.sqf";

should be changed to

 execVM "applywind.sqf";
while {true} do
{
waitUntil{vehicle player isKindOf "Air" && (!(isTouchingGround (vehicle player))) && (((vehicle player) getPosATL select 2) > 5)};
/*10-20 seems to work good, lower _div number to make wind stronger, warning if the wind is to strong you might have trouble flying in certain circumstances.*/
_div = 15;
_unit = vehicle player;
_velocity = velocity _unit;
_unitXV	= _velocity select 0;
_unitYV = _velocity select 1;
_unitZV = _velocity select 2;
_wind_velocity = wind;
_windXV = _wind_velocity select 0;
_windYV = _wind_velocity select 1;
_windZV = _wind_velocity select 2;
       if(_windxv > _unitxv)then
	{
		_unitxv = _unitxv + (_windxv/_div);
	};
	if(_windxv < _unitxv)then
	{
		_unitxv = _unitxv - (_windxv/_div);
	};
	if(_windyv > _unityv)then
	{
		_unityv = _unityv + (_windyv/ _div);
	};
	if(_windyv < _unityv)then
	{
		_unityv = _unityv - (_windyv/_div);
	};
	if(_windzv > _unitzv)then
	{
		_unitzv = _unitzv + (_windzv/_div);
	};
	if(_windzv < _unitzv)then
	{
		_unitzv = _unitzv - (_windzv/_div);
	};
_velocity = [_unitxv, _unityv, _unitzv];
_unit setVelocity _velocity;
sleep 0.1;
};

EDITED: Re-read your code, changed the edits.

Edited by zooloo75

Share this post


Link to post
Share on other sites

thanks for the input zooloo it makes it a lot cleaner, ill update original post, I was tired and wasn't thinking about adding a negative number. I will update the original post with an updated version that should work with mp, haven't tested it mp yet tho. also videos will be put in the original post.

Share this post


Link to post
Share on other sites

going to add slight up and down drafts when flying near slopes. ill probably end up adding autorotation eventually, anyone have any suggestions on stuff to add.

as for multiplayer this should work, the only thing that might need to be done is synchronize everyones wind, because its local to each client. so people probably would end up with different wind direction/strengths.

Share this post


Link to post
Share on other sites

could you post the links to the files themselves... with all the code changes, which is which really... :)

-Raps

Share this post


Link to post
Share on other sites

I tried the apply wind SQF last night. I just put it in the target like you mentioned. Even with slight wind my chopper would move with the wind and I couldn't fly against it.

Share this post


Link to post
Share on other sites

ill throw up a demo mission in a day or so when I get some of the other features I wanted in.

can you please be more specific, because I don't have that issue. with the current settings with full wind and gust you can still fly into the wind(given the speed is decreased to about 130 max), I have also already said some numbers might need tweaking and have already provided an option that you can adjust the wind strength.

Edited by ylguf

Share this post


Link to post
Share on other sites

I put the applywind.SQF in my mission folder. I then put execVM "applywind.sqf"; in the trigger with a trigger covering 3000x3000. I didn't use the heli effects. Do I need to use that as well? My chooper gets swept away by the wind after takeoff with slight wind. I can not fly back against it and gain any ground. I am adjusting the wind in the editor and not the SQF.

Share this post


Link to post
Share on other sites

in the sqf you can change the variable _div to about 20-25 if you want the wind to have less effect without messing with the wind strength in editor. also how is your trigger getting activated? the 3000 x 3000 means nothing. im assuming you have it on repeat when unit present or something. it only needs to get called once, and that's it. if its triggering repeatedly it will cause issues. maybe try creating a "init.sqf" file and put the execVM "applywind.sqf"; command in there. as that's how im doing it and am not having issues. and the heli effects is optional it only adds the vortex ring and settling with power effects. I have a updated version (ill release later) that has all my effects in 1 script so people looking at this in the future might be like what are they talking about multiple sqf's for.

Share this post


Link to post
Share on other sites

big update. hopefully you guys like.

Share this post


Link to post
Share on other sites

I'll give it a try again. I'm looking forward to this! Will this work in an MP mission?

Share this post


Link to post
Share on other sites

i have tested it mp with a few people so it should work. im not sure if wind is a local variable tho so if the wind value is changed you might need to synchronize clients. feedback on what you like and don't like would be nice. I think atm its a bit to hard to autorotate into the wind, as it doesn't produces extra lift but kills speed. so ill fix that.

Share this post


Link to post
Share on other sites

oh yes, alotta like.

I just tried it out in my practice and its great, adds a whole new feel compared to the game engine. I'd love to add this as a player option, although i would really prefer it as default instead : )

Share this post


Link to post
Share on other sites
Wind is local.

just now, as of 0.72, wind is MP synchronized.

also, as of dev branch, they implemented arma2 style autorotations, atleast for now.

Share this post


Link to post
Share on other sites

Juste AWESOME ! exactly what i was searching for! !! So nice. BI can put this in the game it is a shame !

So bad that Aircraft have Ground speed as reference ! But your script is jsut awesome.

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  

×