Spawn plane with driver on air = it crashes
-
Hi, I'm trying to spawn with a C# script a plane, like the Titan, with a driver inside. The driver should drive the plane to a certain point, but instead of it, the plane always crashes, because it falls to the ground (it "dives", is this the word to say when a plane flies directly to the ground?).
I want the plane to continue flying. This is the code I actually have to spawn the plane and the driver. I made a task sequence with two waypoints. A similar code works fine with a helicopter.
Vector3 posTitan = Game.Player.Character.Position.Around(555.0f); posTitan.Z = posTitan.Z + 750.0f; titan = GTA.World.CreateVehicle(VehicleHash.Titan, posTitan); Ped conductor = titan.CreatePedOnSeat(VehicleSeat.Driver, PedHash.Vagos01GFY); TaskSequence ts = new TaskSequence(); Vector3 posTitanDestino1 = posTitan; Vector3 posTitanDestino2 = posTitan; posTitanDestino1.X = posTitan.X + 5000.0f; ts.AddTask.DriveTo(titan, posTitanDestino1, 100.0f, 50.0f); ts.AddTask.DriveTo(titan, posTitanDestino2, 100.0f, 50.0f); ts.Close(true); conductor.AlwaysKeepTask = true; conductor.Task.PerformSequence(ts); UI.ShowSubtitle("Titan spawneado"); titan.AddBlip(); titan.CurrentBlip.Color = BlipColor.Blue;
Thanks in advance!
-
@EnforcerZhukov Your first task tells it to drive to the spawn location... try removing that task so it drives to the second destination instead. It might switch the engine off as it has completed that first task, which might be causing it to drop out of the sky.
Also, but this might not be important... add something that sets the engine to be on, just in case it doesn't get done as part of the DriveTo task.
Not sure how relevant any of that is but it gives you options to try.
-
@EnforcerZhukov said in Spawn plane with driver on air = it crashes:
conductor.AlwaysKeepTask = true;
You're obviously missing a vital line
like eg
conductor.SetStewardessFunction = true;
...sorry no help here
-
@EnforcerZhukov The drive task does not work good on planes. I only use it to taxi on runways. Use TASK_PLANE_MISSION not part of SHVDN so you need to use function calls and unsafe code. In visual studio go to properties build and check Allow unsafe code(if you dont know). Also you can apply force to get them moving after they spawn so they dont dive as much.
Vector3 posTitan = Game.Player.Character.Position.Around(555.0f);
posTitan.Z = posTitan.Z + 750.0f;
Vehicle titan = GTA.World.CreateVehicle(VehicleHash.Titan, posTitan);
Ped conductor = titan.CreatePedOnSeat(VehicleSeat.Driver, PedHash.Vagos01GFY);
titan.ApplyForceRelative(new Vector3(0.0f, 100.0f, 0.0f));
float speed = 100.0f;
float hight = 50.0f;
Vector3 posTitanDestino1 = posTitan;
Vector3 posTitanDestino2 = posTitan;
posTitanDestino1.X = posTitan.X + 5000.0f;
unsafe
{
int seq = 0;
GTA.Native.Function.Call(Hash.OPEN_SEQUENCE_TASK, &seq);
Function.Call(Hash.TASK_PLANE_MISSION, 0, titan, 0, 0, posTitanDestino1.X, posTitanDestino1.Y, posTitanDestino1.Z, 4, 100.0f, 30.0f, -1.0f, hight + 50.0f, hight);
Function.Call(Hash.TASK_PLANE_MISSION, 0, titan, 0, 0, posTitanDestino2.X, posTitanDestino2.Y, posTitanDestino2.Z, 4, 100.0f, 30.0f, -1.0f, hight + 50.0f, hight);
GTA.Native.Function.Call(Hash.SET_SEQUENCE_TO_REPEAT, seq, true);
GTA.Native.Function.Call(Hash.CLOSE_SEQUENCE_TASK, seq);
GTA.Native.Function.Call(Hash.TASK_PERFORM_SEQUENCE, conductor, seq);
GTA.Native.Function.Call(Hash.CLEAR_SEQUENCE_TASK, &seq);
}
UI.ShowSubtitle("Titan spawneado");
titan.AddBlip();
titan.CurrentBlip.Color = BlipColor.Blue;
-
@aimless said in Spawn plane with driver on air = it crashes:
@EnforcerZhukov The drive task does not work good on planes. I only use it to taxi on runways. Use TASK_PLANE_MISSION not part of SHVDN so you need to use function calls and unsafe code. In visual studio go to properties build and check Allow unsafe code(if you dont know). Also you can apply force to get them moving after they spawn so they dont dive as much.
Vector3 posTitan = Game.Player.Character.Position.Around(555.0f);
posTitan.Z = posTitan.Z + 750.0f;
Vehicle titan = GTA.World.CreateVehicle(VehicleHash.Titan, posTitan);
Ped conductor = titan.CreatePedOnSeat(VehicleSeat.Driver, PedHash.Vagos01GFY);
titan.ApplyForceRelative(new Vector3(0.0f, 100.0f, 0.0f));
float speed = 100.0f;
float hight = 50.0f;
Vector3 posTitanDestino1 = posTitan;
Vector3 posTitanDestino2 = posTitan;
posTitanDestino1.X = posTitan.X + 5000.0f;
unsafe
{
int seq = 0;
GTA.Native.Function.Call(Hash.OPEN_SEQUENCE_TASK, &seq);
Function.Call(Hash.TASK_PLANE_MISSION, 0, titan, 0, 0, posTitanDestino1.X, posTitanDestino1.Y, posTitanDestino1.Z, 4, 100.0f, 30.0f, -1.0f, hight + 50.0f, hight);
Function.Call(Hash.TASK_PLANE_MISSION, 0, titan, 0, 0, posTitanDestino2.X, posTitanDestino2.Y, posTitanDestino2.Z, 4, 100.0f, 30.0f, -1.0f, hight + 50.0f, hight);
GTA.Native.Function.Call(Hash.SET_SEQUENCE_TO_REPEAT, seq, true);
GTA.Native.Function.Call(Hash.CLOSE_SEQUENCE_TASK, seq);
GTA.Native.Function.Call(Hash.TASK_PERFORM_SEQUENCE, conductor, seq);
GTA.Native.Function.Call(Hash.CLEAR_SEQUENCE_TASK, &seq);
}
UI.ShowSubtitle("Titan spawneado");
titan.AddBlip();
titan.CurrentBlip.Color = BlipColor.Blue;Thanks, I'll try ASAP!