1010 * None
1111 *
1212 * Example:
13- * bob call ace_common_fnc_fixPosition
13+ * cursorObject call ace_common_fnc_fixPosition
1414 *
1515 * Public: No
1616 */
@@ -21,15 +21,17 @@ if (!local _this) exitWith {};
2121// Objects with disabled simulation and objects with simulation type "house" don't have gravity/physics, so make sure they are not floating
2222private _hasGravity = simulationEnabled _this && {getText (configOf _this >> " simulation" ) ! = " house" };
2323
24- if (! _hasGravity ) then {
25- private _positionASL = getPosASL _this ;
26- // find height of top surface under object
27- private _surfaces = lineIntersectsSurfaces [_positionASL , ATLToASL [_positionASL select 0 , _positionASL select 1 , - 1 ], _this ];
28- if (_surfaces isEqualTo []) exitWith {};
29- private _surfaceHeight = _surfaces select 0 select 0 select 2 ;
30- TRACE_2(" house" ,_this ,_surfaceHeight );
31- if (_positionASL select 2 > _surfaceHeight + 0.1 ) then {
32- _this setPosASL [_positionASL select 0 , _positionASL select 1 , _surfaceHeight ];
24+ private _positionASL = getPosASL _this ;
25+ _positionASL params [" _posX" , " _posY" , " _posZASL" ];
26+ // find top surface under object
27+ private _surfaces = lineIntersectsSurfaces [_positionASL , ATLToASL [_posX , _posY , - 1 ], _this ];
28+
29+ TRACE_3(" fixPosition" ,_this ,_hasGravity ,_surfaces );
30+
31+ if (! _hasGravity && {_surfaces isNotEqualTo []}) then {
32+ private _surfaceHeightASL = _surfaces select 0 select 0 select 2 ;
33+ if (_posZASL > _surfaceHeightASL + 0.1 ) then {
34+ _this setPosASL [_posX , _posY , _surfaceHeightASL ];
3335 };
3436};
3537
@@ -41,8 +43,19 @@ if (_position select 2 < -0.1) then {
4143 _this setPosATL _position ;
4244};
4345
44- // Adjust position to sloped terrain , if placed on ground
46+ // Adjust position to sloped surface , if placed on ground
4547// Object without gravity/physics may have negative height when placed on slope, but those objects are definitely on the ground
4648if (! _hasGravity || {getPosATL _this select 2 == _position select 2 }) then {
47- _this setVectorUp surfaceNormal _position ;
49+ private _normal = if (_surfaces isEqualTo []) then {
50+ surfaceNormal _position
51+ } else {
52+ private _surfaceNormal = _surfaces select 0 select 1 ;
53+ // on flipped surfaces fallback to terrain
54+ if (_surfaceNormal select 2 > 0 ) then {
55+ _surfaceNormal
56+ } else {
57+ surfaceNormal _position
58+ }
59+ };
60+ _this setVectorUp _normal ;
4861};
0 commit comments