Jump to content
Sign in to follow this  
metalcraze

How to: semi-realistic auto-hover for Apache

Recommended Posts

Basically the idea is to remove the "auto-hover" player action when the speed is higher than 18 kmph and bring it back when the speed is within 18 kmph (or at least stop player from turning it on with those conditions in mind). And also auto-disable it when the speed exceeds 18 kmph if it's turned on.

Any ideas how to implement this through CPP or, preferably, SQF? To keep missions addon free and because auto-hover is all too arcadey right now even though Apache flight physics are quite adequate.

Share this post


Link to post
Share on other sites

Now that's a pretty decent idea metalcraze. Bravo !

I have NO idea how to help you however.

Share this post


Link to post
Share on other sites

I try not to use it myself (auto hover) but I do sometimes accidentally engage it at high speed... same with F-35. Good idea and good luck. :)

Share this post


Link to post
Share on other sites

What I do now is put a trigger with the condition

speed apache > 18 || speed apache < -18;

OnAct:

player action ["AutoHoverCancel", apache];

What this does is disabling AutoHover when chopper exceeds the speed of 18 kmph. However despite me setting the trigger to multiple activations it only works when the speed goes below 18 and then back up again. Meaning I can activate auto-hover all I want at high speeds.

Any suggestions about how to force the trigger to constantly repeat auto-hover cancellation as long as the speed is higher than 18?

What I also like about this implementation is that now to cancel auto-hovering (in case of being attacked by an RPG f.e.) you don't need to scroll through menu or push a button - you can just move forward immediately (that's how it works in the real chopper as well)

Edited by metalcraze

Share this post


Link to post
Share on other sites

That's because the trigger only resets after the condition has changed state (true->false or false->true). You're better off spawning some code with a while loop.

Ex:

0 = apache spawn {while{alive _this}do{if((driver _this == player) && (abs(speed _this) > 18))then{player action ["AutoHoverCancel",_this]}}}

Edited by Big Dawg KS

Share this post


Link to post
Share on other sites

I think I did it with a trigger after all:

A trigger with multiple activations

Condition:

speed apache < -18 || speed apache > 18

OnAct

null = [] spawn
{
   while {speed apache < -18 || speed apache > 18} do
   {
        player action ["AutoHoverCancel", apache];
   };
};

Now auto-hover command is completely ignored unless speed is below 18.

Need to test this more though.

Thanks for your example anyway - but here is a more correct version

null = ap1 spawn {while{alive _this} do {if((driver _this == player) && ((abs(speed _this) > 18) || (abs(speed _this) <-18))) then {player action ["AutoHoverCancel",_this]}}}

Don't forget that Apache can also accelerate backwards and have "-18" speed in game which turns off auto-hover as well.

Now it's closer to the real thing.

Edited by metalcraze

Share this post


Link to post
Share on other sites

Will try this later.

Now, will this work for ALL apaches, cobras, lynx etc? Is there a way to make it ubiquitous? Also will this work with newly spawned helos, even if they aren't named?

Finally, how can this work for AI controlled choppers?

Share this post


Link to post
Share on other sites

It will work for all aircrafts that have an auto-hover option. If you want more realism - it's a good idea to check whether an aircraft supports autohover and at which speeds in reality - then you can modify the code accordingly, down to disabling auto-hover completely

AI controlled choppers don't use auto-hover.

It should work with anything even non-named, just replace the 'ap1' with 'this' in its init

Edited by metalcraze

Share this post


Link to post
Share on other sites

Thanks for info. I had problems with this, in that I first of all turn on Autohover, then move forward and it removes that autohover - good. Now what I want is that when I slow back down again (speed <18) it re-engages the autohover (without my input). How can that be done ?

Share this post


Link to post
Share on other sites

You add a similar code to what we already have, except modified a bit so the whole init field will look like this:

null = this spawn {while{alive _this} do {if((driver _this == player) && ((abs(speed _this) > 18) || (abs(speed _this) < -18))) then {player action ["AutoHoverCancel",_this]}}}; 
null = this spawn {while{alive _this} do {if((driver _this == player) && ((abs(speed _this) <= 18) && (abs(speed _this) >= -18))) then {player action ["AutoHover",_this]}}}

It was a quick solution so there should be a way to make this code less messy

Share this post


Link to post
Share on other sites

I can't test it now, work.

But try putting this at the init file and it should work with any Helicopter u'll get in as pilot.

[] spawn {
 while (alive player) do
   {
    if (local player && driver vehicle player == player && vehicle player != player && vehicle player iskindof "Helicopter") then
      {
       if((abs(speed vehicle player ) > 18) || (abs(speed vehicle player ) < -18))  then
         {
          player action ["AutoHoverCancel",vehicle player ];
          } else
            {
             player action ["AutoHover",_this];
             };
        };
     sleep 0.05;
    };
  };

Share this post


Link to post
Share on other sites
Thanks for your example anyway - but here is a more correct version

null = ap1 spawn {while{alive _this} do {if((driver _this == player) && ((abs(speed _this) > 18) || (abs(speed _this) <-18))) then {player action ["AutoHoverCancel",_this]}}}

Don't forget that Apache can also accelerate backwards and have "-18" speed in game which turns off auto-hover as well.

Now it's closer to the real thing.

Um... it seems you didn't notice, but the abs command returns the absolute value of the speed; whether it's -18 or 18, abs makes it always positive. So your or statement is unneeded, and my original code was correct.

Share this post


Link to post
Share on other sites

Finally had some time to test it.

Well put this in the inif.sqf file in the mission folder. If you don't have any, make one.

[] spawn {
 while {true} do
   {
    if (driver vehicle player == player  && vehicle player iskindof "Helicopter") then
      {
       if((abs(speed vehicle player ) > 18) || (abs(speed vehicle player ) < -18))  then
         {
          player action ["AutoHoverCancel",vehicle player ];
          } else
            {
             player action ["AutoHover",vehicle player];
             };
        };
     sleep 0.05;
    };
  };

Share this post


Link to post
Share on other sites

Again, you should either get rid of the abs or just remove the the -18 check; it's totally unneeded if you're getting the absolute value of the speed.

Share this post


Link to post
Share on other sites

Good idea lads.

And thanks Big Dawg for helping out. Will test your line. :)

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  

×