Jump to content
Sign in to follow this  
IndeedPete

Spawned Plane Crashes Instantly

Recommended Posts

Hey,

I'm having a weird problem. In a few missions I'm spawning flying planes. While the code works fine in 50% of the cases the planes just crash on start in the other half of the cases. They just fall down. I assume this has something to do with setDir in combination with the velocity they have when being spawned as "Fly". E.g. the oginal velocity pulls the machine north but the setDir turns it around so the pilot can't stabilise the machine and it crashes. For reference, some example code from one of my missions below:

_pos = getMarkerPos "mCSATAirSpawn0";
_dir = markerDir "mCSATAirSpawn0";
_grpPlane = createGroup east;
_plane = createVehicle ["O_Plane_CAS_02_F", _pos, [], 0, "FLY"];
_plane setDir _dir;
[_plane, _grpPlane] call BIS_fnc_spawnCrew;

Any ideas? Maybe a small fomular to calculate the correct velocity from the given dir?

Any help appreciated!

Share this post


Link to post
Share on other sites

A lot of people seem to be having this problem lately, I've tried all I can to help (theoretically). I guess I'll just have to whip up a quick mission. Or could you post your mission and I'll test it?

Share this post


Link to post
Share on other sites

Thanks for your help! I can't post the mission(s) in question as they're all tied to rather complex campaign systems means you'd need to fiddle around in tons of scripts and functions. But I could make up a quick test scenario if that helps. Will cobble something together later.

---------- Post added at 01:53 AM ---------- Previous post was at 01:39 AM ----------

There we go: https://www.dropbox.com/s/qj4mrm8qboiisq8/PlaneCrashTest.VR.rar?dl=0

---------- Post added at 01:53 AM ---------- Previous post was at 01:53 AM ----------

Just a smal arsenal mission where the above code is implemented as action. Plus it increases the marker dir by 30 every time.

Share this post


Link to post
Share on other sites

_plane  setVelocity [100 * (sin (getdir _plane)), 100 * (cos (getdir _plane )), 1];

I was also going to suggest to remove the setDir because that is what is causing your plane to crash, because setDir instantly removes the vehicles velocity, so we need to do some setVelocity to add it back again.

Play around with the numbers in the setVelocity code.

Good Luck!

Share this post


Link to post
Share on other sites

If you spawn it up fairly high it has the time to fall and gain the momentum it needs to pull out of the dive.

Share this post


Link to post
Share on other sites

Have you double checked if the pilot gets spawned correctly?

My gut-feeling tells me that this might be the issue.

ps.: You could also try the command "createVehicleCrew" instead of BIS_fnc_spawnCrew

Share this post


Link to post
Share on other sites

@Lala14: Thanks, I'll try that!

@MoFo: Might be an option but it's not pretty. I'd love them to just spawn in the air, moving in the given dir without any troubles.^^

@Tajin: A pilot is definitely spawned. Also in similar scripts where I have the same problem but spawn the pilot manually. Will try nontheless, thanks!

Share this post


Link to post
Share on other sites

This is working for me on other Islands besides VR.

player addAction ["Spawn Plane", {
(_this select 1) removeAction (_this select 2);// added this to allow execute from debug again after edits and use one action.
_speed = 180;
_height = 50;
"mCSATAirSpawn0" setMarkerDir ((markerDir "mCSATAirSpawn0") + 30);
_pos = getMarkerPos "mCSATAirSpawn0";
_dir = markerDir "mCSATAirSpawn0";

_vehicle = [_pos, _dir, "O_Plane_CAS_02_F", EAST] call bis_fnc_spawnvehicle;
sleep 0.1;
_veh = _vehicle select 0;
_vehgrp = _vehicle select 2;

_vel = velocity _veh;
_veh setpos [(_pos select 0) + (sin (_dir -180)), (_pos select 1) + (cos (_dir -180)), _height];
_veh setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)];	
}];

Edited by Jigsor

Share this post


Link to post
Share on other sites

I wonder how the game editor does this, since it never has this problem.

Share this post


Link to post
Share on other sites
I wonder how the game editor does this, since it never has this problem.

direction is defined in mission.sqm class for editor placed object

Share this post


Link to post
Share on other sites

Hm, sorry to dig out this thread again but KK's fix doesn't seem to work for some people. Since I've applied it to my mission the problem is completely gone for me, no way of reproducing it. And based on user feedback it's settled for most of my players as well. However, I still get reports from like two or three people that on their machines the plane is still going down - every time, making the mission impossible to play for these people. Any idea what it might be? As said, I can't reproduce it, it's insanely weird!

Share this post


Link to post
Share on other sites

First reporter claims it happens one time, then he reloads an autosave and then the plane flies as planned. Still waiting for the second reporter's answer. I could swear there was another one claiming to have this issue every time he reloads, not sure though if he played the updated version containing your fix. Just for reference here is the whole cutscene with plane spawn from my missionFlow.fsm. As I said, it's working fine for me, marked the creation part in red, IP_fnc_setDirFly is just your code snippet implemented into my CfgFunctions.

_handle = [] spawn {
[iP_Main, "Gamemaster, this is Eightball. I'm in position, send in CAS, over.", "SIDE"] call IP_fnc_simpleSentence;
[iP_HQ, "Copy that, Eightball. Stand-by, air assets are now entering your airspace, callsign 'Badass', over.", "SIDE"] call IP_fnc_simpleSentence;
["tOverview", "SUCCEEDED"] call BIS_fnc_taskSetState;
saveGame;

["IP_BlackScreen", false] call BIS_fnc_blackOut;
sleep 0.5;

if (player getVariable ["IP_Glass_Boot", false]) then {[] call IP_fnc_GlassBoot};

{
	_x allowDamage false;
	_x enableSimulation false;
} forEach (units group IP_Main);
enableSentences false;

[color="#FF0000"][b]_posTarget = getMarkerPos "mHQ";
_posStart = getMarkerPos "mPlane1";
_dir = [_posStart, _posTarget] call BIS_fnc_dirTo;
_grp = createGroup west;
_grp setGroupID ["Badass One"];

IP_Pilot = _grp createUnit ["B_Pilot_F", _posStart, [], 0, "NONE"];
IP_Pilot setRank "CAPTAIN";
IP_Pilot setVariable ["IP_Faction", "EFMil"];
IP_Pilot setIdentity "planePilot";
IP_Pilot setVariable ["IP_Avatar", "Campaigns\IP_CMP_MERCS\img\planePilotAvatar.jpg"];
IP_Pilot linkItem "NVGoggles";
[iP_Pilot, 5] call IP_fnc_setSkill;

IP_Plane = createVehicle ["B_Plane_CAS_01_F", _posStart, [], 0, "FLY"];
[iP_Plane, _dir] call IP_fnc_setDirFly; // IP_Plane setDir _dir;
IP_Plane setObjectTexture [0, "Campaigns\IP_CMP_MERCS\txt\plane_cas_01_ext01_coEF1.paa"];
IP_Plane setObjectTexture [1, "Campaigns\IP_CMP_MERCS\txt\plane_cas_01_ext02_coEF1.paa"];
IP_Pilot moveInDriver IP_Plane;
IP_Plane enableSimulation false;

_wp = _grp addWaypoint [_posTarget, 0];
_wp setWaypointType "SAD";
[_grp, 0] setWaypointBehaviour "COMBAT";
[_grp, 0] setWaypointCombatMode "RED";

_posStart = getMarkerPos "mPlane2";
_grp = createGroup west;
_grp setGroupID ["Badass Two"];

IP_Pilot2 = _grp createUnit ["B_Pilot_F", _posStart, [], 0, "NONE"];
IP_Pilot2 setRank "LIEUTENANT";
IP_Pilot2 setVariable ["IP_Faction", "EFMil"];
//IP_Pilot2 setName "";
IP_Pilot2 allowDamage false;
[iP_Pilot2, 5] call IP_fnc_setSkill;

IP_Plane2 = createVehicle ["B_Plane_CAS_01_F", _posStart, [], 0, "FLY"];
[iP_Plane2, _dir] call IP_fnc_setDirFly; // IP_Plane2 setDir _dir;
IP_Plane2 setObjectTexture [0, "Campaigns\IP_CMP_MERCS\txt\plane_cas_01_ext01_coEF1.paa"];
IP_Plane2 setObjectTexture [1, "Campaigns\IP_CMP_MERCS\txt\plane_cas_01_ext02_coEF2.paa"];
IP_Pilot2 moveInDriver IP_Plane2;
IP_Plane2 enableSimulation false;
IP_Plane2 allowDamage false;

_wp = _grp addWaypoint [_posTarget, 0];
_wp setWaypointType "SAD";
[_grp, 0] setWaypointBehaviour "COMBAT";
[_grp, 0] setWaypointCombatMode "RED";[/b][/color]

_camera = "camera" camCreate (getPos player);
_camera cameraEffect ["internal", "back"];

waitUntil{preloadCamera (getPos IP_Plane)};	

IP_Camera = _camera;
_scene = {
	IP_Camera camSetTarget IP_Plane;
	IP_Camera camSetRelPos [0, -15, 5];
	IP_Camera camPrepareFOV 0.700;
	IP_Camera camCommitPrepared 0;
};
["IP_OnEachFrameEH", "onEachFrame", _scene] call BIS_fnc_addStackedEventHandler;

{
	_x enableSimulation true;
	_x addEventhandler ["Fired", {
		if ((_this select 1) == "Bomb_04_Plane_CAS_01_F") then {
			(_this select 6) spawn {
				private "_pos";
				while {!isNull _this} do {
					_pos = getPos _this;
					sleep 0.03;
				};

				sleep 0.5;

				for "_i" from 0 to 10 do {
					_spreadPos = [_pos, 25] call SHK_pos;
					_spreadPos set [2, 1];
					_shell = "Bo_GBU12_LGB_MI10" createVehicle _pos;
					[_shell, -90, 0] call BIS_fnc_setPitchBank;
					_shell setVelocity [0, 0, -100]; 
				};
			};
		};
	}];
} forEach [iP_Plane, IP_Plane2];

sleep 0.5;
["IP_BlackScreen"] call BIS_fnc_blackIn;

[iP_HQ, "Badass One, Badass Two, this is Gamemaster, report, over.", "SIDE"] call IP_fnc_simpleSentence;
[iP_Pilot, "Badass One, Badass Two reporting. We're ten clicks off the AO, approaching from the north-east. How copy, Gamemaster? Over.", "SIDE"] call IP_fnc_simpleSentence;
[iP_HQ, "Gamemaster copies, what's your status, over?", "SIDE"] call IP_fnc_simpleSentence;

["IP_BlackScreen", false] call BIS_fnc_blackOut;
sleep 0.5;

["IP_OnEachFrameEH", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
IP_InCutscene = false;
sleep 0.5;
IP_InCutscene = true;

_scene = {
	IP_Camera camSetTarget IP_Plane;
	IP_Camera camSetRelPos [-5, 10, -1];
	IP_Camera camPrepareFOV 0.700;
	IP_Camera camCommitPrepared 0;
};
["IP_OnEachFrameEH", "onEachFrame", _scene] call BIS_fnc_addStackedEventHandler;

sleep 0.5;
["IP_BlackScreen"] call BIS_fnc_blackIn;

[iP_Pilot, "Badass One, Badass Two, all within normal parameters. Weapon systems online, engine running, no visuals on target yet. I'd say we're good to go, over.", "SIDE"] call IP_fnc_simpleSentence;
[iP_HQ, "Copy that Badass, you've got clearance to engage at will. Weapons free and Waidmannsheil, over!", "SIDE"] call IP_fnc_simpleSentence;
[iP_Pilot, "Thanks, Gamemaster! Badass One, Badass Two engaging, over.", "SIDE"] call IP_fnc_simpleSentence;

["IP_BlackScreen", false] call BIS_fnc_blackOut;
sleep 0.5;

["IP_OnEachFrameEH", "onEachFrame"] call BIS_fnc_removeStackedEventHandler;
IP_InCutscene = false;
sleep 0.5;

_camera cameraEffect ["terminate", "back"];
camDestroy _camera;

selectPlayer IP_Pilot;
{
	if (!IP_TESTMODE) then {_x allowDamage true};
	_x enableSimulation true;
} forEach (units group IP_Main);
enableSentences true;

{_x limitSpeed 1000} forEach [iP_Plane, IP_Plane2];
{[_x] call IP_fnc_track} forEach [iP_Pilot, IP_Pilot2];

sleep 0.5;
["IP_BlackScreen"] call BIS_fnc_blackIn;

[player, "tDestroy", ["Destroy the <marker name=""mHQ"">AAF Headquarters</marker> and engage additional enemy assets as you see fit!", "Destroy AAF Headquarters", "AAF Headquarters"], "mHQ", true, 1] call BIS_fnc_taskCreate;
saveGame;	

sleep 1;
[iP_Pilot, "Okay, let's show these Greenback assholes some democracy!", "DIRECT"] call IP_fnc_simpleSentence;
[["MERCS", "BadassTeamswitch"]] call BIS_fnc_advHint;
{addSwitchableUnit _x} forEach [iP_Main, IP_Pilot];
//IP_LaseTargets = false;
};

Thanks again for your quick response and help on this matter!

Share this post


Link to post
Share on other sites

The whole script is scheduled, expect surprises. I'd move everything to FSM if I were you.

Share this post


Link to post
Share on other sites

Hm, but what about the sleep commands then?

Oh, and I've noticed there was some other velocity related piece of code later on. Must be a leftover from several tries to fix the problem. I should update the published version and see if removing it helps.

Share this post


Link to post
Share on other sites

All I can say is that I had similar problem before using scheduled script. It was meant to open parachute for a player on spawn, and it used to fail randomly, seemed to be connected to script engine schedule. After all the engine is free to suspend your script in the middle of execution for undefined amount of time. You can imagine how this could lead to some nasty surprises.

Share this post


Link to post
Share on other sites

Hm, I now left out the whole spawn part and just placed down the raw planes, simulation disabled. I hope that works better, thanks again!

Share this post


Link to post
Share on other sites
Does this happen every time for these people or sometimes?

I'm one of the reporters, and it happened always for me. Well, the six or seven times I tried :P.

Share this post


Link to post
Share on other sites

I find this line cause the plane to crash

waitUntil{preloadCamera (getPos IP_Plane)};

I don't really understand cameras

Share this post


Link to post
Share on other sites

as much as I could get working. I don't have the all the functions.

Basically the plane is stalling and probably needs some velocity to get it up to speed.

Share this post


Link to post
Share on other sites
I'm one of the reporters, and it happened always for me. Well, the six or seven times I tried :P.

Try verifying integrity of game cache maybe.

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  

×