2015-03-16 18:25:29 +00:00
|
|
|
/*
|
2017-10-01 18:38:11 +00:00
|
|
|
* Author: commy2, Jonpas
|
2015-03-16 18:25:29 +00:00
|
|
|
* Fixes position of an object. E.g. moves object above ground and adjusts to terrain slope. Requires local object.
|
|
|
|
*
|
2016-06-18 09:50:41 +00:00
|
|
|
* Arguments:
|
2015-09-20 14:56:35 +00:00
|
|
|
* Object <OBJECT>
|
2015-03-16 18:25:29 +00:00
|
|
|
*
|
2015-09-20 14:56:35 +00:00
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
2017-10-01 18:38:11 +00:00
|
|
|
* bob call ace_common_fnc_fixPosition
|
2017-06-08 13:31:51 +00:00
|
|
|
*
|
2015-09-20 14:56:35 +00:00
|
|
|
* Public: No
|
2015-03-16 18:25:29 +00:00
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
// setVectorUp requires local object
|
|
|
|
if (!local _this) exitWith {};
|
|
|
|
|
2017-10-01 18:38:11 +00:00
|
|
|
// Objects with disabled simulation and objects with simulation type "house" don't have gravity/physics, so make sure they are not floating
|
2017-11-04 16:05:33 +00:00
|
|
|
private _hasGravity = simulationEnabled _this && {getText (configFile >> "CfgVehicles" >> typeOf _this >> "simulation") != "house"};
|
2017-10-01 18:38:11 +00:00
|
|
|
|
|
|
|
if (!_hasGravity) then {
|
2018-01-15 18:02:06 +00:00
|
|
|
private _positionASL = getPosASL _this;
|
|
|
|
// find height of top surface under object
|
|
|
|
private _surfaces = lineIntersectsSurfaces [_positionASL, ATLToASL [_positionASL select 0, _positionASL select 1, -1], _this];
|
|
|
|
if (_surfaces isEqualTo []) exitWith {};
|
|
|
|
private _surfaceHeight = _surfaces select 0 select 0 select 2;
|
|
|
|
TRACE_2("house",_this,_surfaceHeight);
|
|
|
|
if (_positionASL select 2 > _surfaceHeight + 0.1) then {
|
|
|
|
_this setPosASL [_positionASL select 0, _positionASL select 1, _surfaceHeight];
|
2016-03-02 00:49:41 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-10-01 18:38:11 +00:00
|
|
|
private _position = getPosATL _this;
|
2015-03-16 18:25:29 +00:00
|
|
|
|
2017-10-01 18:38:11 +00:00
|
|
|
// Don't place the object below the ground
|
2015-03-18 12:36:22 +00:00
|
|
|
if (_position select 2 < -0.1) then {
|
|
|
|
_position set [2, -0.1];
|
2017-10-01 18:38:11 +00:00
|
|
|
_this setPosATL _position;
|
2015-03-16 18:25:29 +00:00
|
|
|
};
|
|
|
|
|
2017-10-01 18:38:11 +00:00
|
|
|
// 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 {
|
2015-03-16 18:25:29 +00:00
|
|
|
_this setVectorUp surfaceNormal _position;
|
|
|
|
};
|