ACE3/addons/common/functions/fnc_fixPosition.sqf
jonpas 711e1fc026 Fix Underwater interactions (magrepack, loading, refuel, medical legs, dragging) (#5521)
* Fix Magazine Repack underwater - fix #5513
Also prevent common goKneeling function underwater

* Fix loading patients underwater - fix #5515

* Fix load object underwater

* Fix take nozzle on jerry can underwater

* Fix refuel underwater conditions further

* Use isTouchingGround, Make refuel semi-compatible
 reports false if head is out of the water, we want true even if we are not diving

* Less interact exceptions duplication

* Use animationState to determine if unit is swimming, create common function and use it instead of isTouchingGround

* Fix condition

* Support dragging underwater
No carrying due to animation timing issues and other misc things

* Allow Medical Legs SelfActions underwater

* Fix fixPosition function underwater (use getPosATL instead of getPos)

* Fix fixPosition's slope adjustment for non-gravity objects, Do the same for objects without simulation as well
2017-10-01 13:38:11 -05:00

46 lines
1.4 KiB
Plaintext

/*
* Author: commy2, Jonpas
* Fixes position of an object. E.g. moves object above ground and adjusts to terrain slope. Requires local object.
*
* Arguments:
* Object <OBJECT>
*
* Return Value:
* None
*
* Example:
* bob call ace_common_fnc_fixPosition
*
* Public: No
*/
#include "script_component.hpp"
// setVectorUp requires local object
if (!local _this) exitWith {};
// Objects with disabled simulation and objects with simulation type "house" don't have gravity/physics, so make sure they are not floating
private _hasGravity = simulationEnabled _this && {!(getText (configFile >> "CfgVehicles" >> typeOf _this >> "simulation") == "house")};
if (!_hasGravity) then {
private _posAbove = (getPosATL _this) select 2;
TRACE_2("house",_this,_posAbove);
if (_posAbove > 0.1) then {
private _newPosATL = (getPosATL _this) vectorDiff [0, 0, _posAbove];
_this setPosATL _newPosATL;
};
};
private _position = getPosATL _this;
// Don't place the object below the ground
if (_position select 2 < -0.1) then {
_position set [2, -0.1];
_this setPosATL _position;
};
// Adjust position to sloped terrain, if placed on ground
// Object without gravity/physics may have negative height when placed on slope, but those objects are definitely on the ground
if (!_hasGravity || {getPosATL _this select 2 == _position select 2}) then {
_this setVectorUp surfaceNormal _position;
};