Jump to content
Sign in to follow this  
pexmo

Locking AI pilot on current heading and altitude?

Recommended Posts

Hello.

I currently am using a script that lets me switch between gunner and pilot within a helicopter, as well as from pilot of a strike aircraft to a ground soldier. What I would like to add is something that, when the AI unit switches seat with me he will :

- Be locked to fly at current altitude, thus somehting that gathers the helicopters current alt and sets it at flyatheight or something like that.

- Maintain current heading and speed (speed is not that relevant as long as it is quite slow).

Anyone that can help me with this?

---------- Post added at 06:41 ---------- Previous post was at 05:39 ----------

I guess this would involve reading current pitch and altitude and then transfer it to the ai and lock him to that

Share this post


Link to post
Share on other sites

You can get the current altitude with getPosATL/ASL using the third value in the returning array.

getAltitude = {
   private "_altitude";
   _altitude = getPosATL _this;
   if (surfaceIsWater _altitude) then
   {
       _altitude = getPosASL _this;
   };
   _altitude select 2; 
};

Using this information, you can easily save the altitude in the moment when you change the pilot and check if the current one is under that threshold:

_altitudeOnPilotChange = _vehicle call getAltitude;

while {driver _vehicle != player && alive _vehicle} do 
{
   if ( (_vehicle call getAltitude) <  _altitudeOnPilotChange ) then
   {
       (driver _vehicle) flyInHeight _altitudeOnPilotChange;
   };

   sleep 0.5;
};

To maintain the current heading is a little bit tricky, you have to consider the velocity vector as well as the up/direction vector.

Whenever vectors are involved the calculations can get out of hand very quickly so here's another approach: How about dynamically creating a Waypoint for the AI driver which is 10~20km in front of the heli?

This way the AI will fly straight and you can set the speed to "Slow" or "Normal" and set some other attributes along the way.

To dynamically add a waypoint in front of your helo, use this code:

_flyByWaypoint = (group (driver _vehicle)) addWaypoint [_vehicle modelToWorld [0, 15000, 0], 0];
_flyByWaypoint setWaypointSpeed "LIMITED"; // slow
_flyByWaypoint setWaypointType "MOVE"; // start moving

Now if you combine all these codes, you'll get something pretty close to your request.

PS: don't forget to delete the waypoint after you've changed pilot seats again!

Edited by XxAnimusxX

Share this post


Link to post
Share on other sites

Ah thanks alot Animus! Will try to incorporate all that into what I have and see how it works out, guess a hover ccould be achieved as well by placing the waypoint 0meters from the helicopter.

One question though: How do I go about to delete the created waypoint?

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  

×