diff --git a/addons/spottingscope/functions/fnc_place.sqf b/addons/spottingscope/functions/fnc_place.sqf index 21560f948f..d967627fb8 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;