Jump to content
Tory Xiao

createVehicle a plane and make it fly

Recommended Posts

Im trying to edit the a3wasteland mission to make planes bought from vehicle store spawn mid-air with some velocity. Here is part of the SQF handling it:

in spawnStoreObject.sqf:

if (_player getVariable ["cmoney", 0] >= _itemPrice) then
		{
			private _markerPos = markerPos _marker;
			private _npcPos = getPosASL _storeNPC;
			private _canFloat = (round getNumber (configFile >> "CfgVehicles" >> _class >> "canFloat") > 0);
			private _waterNonBoat = false;
			private "_spawnPosAGL";

			// non-boat spawn over water (e.g. aircraft carrier)
			if (!isNull _storeNPC && surfaceIsWater _npcPos && !_seaSpawn) then
			{
				_markerPos set [2, _npcPos select 2];
				_spawnPosAGL = ASLtoAGL _markerPos;
				_safePos = if (_canFloat) then { _spawnPosAGL } else { ASLtoATL _markerPos };
				_waterNonBoat = true;
			}
			else // normal spawn
			{
				_safePos = _markerPos findEmptyPosition [0, 50, [_class, "B_Truck_01_transport_F"] select (!surfaceIsWater _markerPos && _seaSpawn)]; // use HEMTT in findEmptyPosition for boats on lands 
				if (count _safePos == 0) then { _safePos = _markerPos };
				_spawnPosAGL = _safePos;
				if (_seaSpawn) then { _safePos vectorAdd [0,0,0.05] };
			};

			// delete wrecks near spawn
			{
				if (!alive _x) then
				{
					deleteVehicle _x;
				};
			} forEach nearestObjects [_spawnPosAGL, ["LandVehicle","Air","Ship"], 25 max sizeOf _class];

			if (_player getVariable [_timeoutKey, true]) then { breakOut "spawnStoreObject" }; // Timeout
			
			_results1 = (call planesArray) select {_x select [1,999] isEqualTo _itemEntrySent}; //飞机空中出生
			
			if (count _results1 > 0) then {
			_object = createVehicle [_class, [_markerPos select 0, _markerPos select 1, 800], [], 50, "FLY"];
			//_object setVelocity [300,0,0];
			_player moveInDriver _object;
			}else{
			_object = createVehicle [_class, _safePos, [], 0, "NONE"];
			};


			if (_waterNonBoat && _object isKindOf "plane") then
			{
				private _posSurf = getPos _object;
				private _posASL = getPosASL _object;

				if (_posSurf select 2 < 0) then
				{
					_object setVelocity [300,0,0];
					_object setPosASL [_posSurf select 0, _posSurf select 1, (_posASL select 2) - (_posSurf select 2) + 800];
				};
			};
			
			if (_waterNonBoat && _object isKindOf "helicopter") then
			{
				private _posSurf = getPos _object;
				private _posASL = getPosASL _object;

				if (_posSurf select 2 < 0) then
				{
					_object setPosASL [_posSurf select 0, _posSurf select 1, (_posASL select 2) - (_posSurf select 2) + 0.05];
				};
			};

You can see here I spawned the vehicle that is plane with 

_object = createVehicle [_class, [_markerPos select 0, _markerPos select 1, 800], [], 50, "FLY"];

and set it's position and velocity with 

_object setVelocity [300,0,0];
_object setPosASL [_posSurf select 0, _posSurf select 1, (_posASL select 2) - (_posSurf select 2) + 800];

But in game the plane spawn at only 100m high and with 0 speed, crashed immediately. WHY???

Share this post


Link to post
Share on other sites

turn on -showScriptErrors startup parameter to see if there's errors

 

Also "if (_posSurf select 2 < 0) then" line looks like part of the problem, why condition at all? I don't know what you are trying achieve with rest of the z math

  • Like 1

Share this post


Link to post
Share on other sites

_object setVelocityModelSpace [0,300,0];  (set it  to Y ; 150 is far enough in m/s)

  • Like 1

Share this post


Link to post
Share on other sites

@Tory Xiao, try to use this code snippet,

_direction = getDir _object;

_object setVelocity [100 * (sin _direction), 100 * (cos _direction), 0];

AFTER setting up position.

Regarding

1 hour ago, Tory Xiao said:

But in game the plane spawn at only 100m high

according to BIKI,

Quote

The default flying altitude is 100 meters.

There seems to be something wrong with height passed to setPos command.

  • Like 1

Share this post


Link to post
Share on other sites

Corrected my post above for setVelocityModelSpace (it was obvious but I missed it!)

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

×