From a12d9dc2fbf1916ed0cafacae882f04ebb706624 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 13 Jun 2016 16:51:28 -0300 Subject: [PATCH] Attempt aof fixing the placement of spotting scopes on slopes --- addons/spottingscope/functions/fnc_place.sqf | 29 +++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/addons/spottingscope/functions/fnc_place.sqf b/addons/spottingscope/functions/fnc_place.sqf index 21560f948f7..d967627fb85 100644 --- a/addons/spottingscope/functions/fnc_place.sqf +++ b/addons/spottingscope/functions/fnc_place.sqf @@ -27,15 +27,30 @@ if ((_unit call CBA_fnc_getUnitAnim) select 0 == "stand") then { [{ params ["_unit"]; - private ["_direction", "_position", "_spottingScope"]; - _direction = getDir _unit; - _position = (getPosASL _unit) vectorAdd [0.8 * sin(_direction), 0.8 * cos(_direction), 0.02]; + // prevent collision damage + [QEGVAR(common,fixCollision), _unit] call CBA_fnc_localEvent; - _spottingScope = "ACE_SpottingScopeObject" createVehicle [0, 0, 0]; + // Check for a place to land the spotting scope + private _direction = getDir _unit; + private _position = (getPosASL _unit) vectorAdd [0.8 * sin(_direction), 0.8 * cos(_direction), 0]; + private _vectorUp = [0, 0, 1]; + private _intersections = lineIntersectsSurfaces [_position vectorAdd [0, 0, 1.5], _position vectorDiff [0, 0, 1.5], _unit, objNull, true, 1, "GEOM", "FIRE"]; + if (_intersections isEqualTo []) then { + TRACE_1("No intersections",_intersections); + } else { + (_intersections select 0) params ["_touchingPoint", "_surfaceNormal"]; + _position = _touchingPoint vectorAdd [0, 0, 0.05]; + _vectorUp = _surfaceNormal; + }; + + // Create the scope and set its position and orientation + private _spottingScope = "ACE_SpottingScopeObject" createVehicle [0, 0, 0]; _spottingScope setDir _direction; _spottingScope setPosASL _position; - if ((getPosATL _spottingScope select 2) - (getPos _spottingScope select 2) < 1E-5) then { - _spottingScope setVectorUp (surfaceNormal (position _spottingScope)); - }; + _spottingScope setVectorUp _vectorUp; + [QEGVAR(common,fixPosition), _spottingScope, _spottingScope] call CBA_fnc_targetEvent; + [QEGVAR(common,fixFloating), _spottingScope, _spottingScope] call CBA_fnc_targetEvent; + _unit reveal _spottingScope; + }, [_unit], 1, 0] call CBA_fnc_waitAndExecute;