Attempt aof fixing the placement of spotting scopes on slopes

This commit is contained in:
esteldunedain 2016-06-13 16:51:28 -03:00
parent 11dc3bd71a
commit a12d9dc2fb

View File

@ -27,15 +27,30 @@ if ((_unit call CBA_fnc_getUnitAnim) select 0 == "stand") then {
[{ [{
params ["_unit"]; params ["_unit"];
private ["_direction", "_position", "_spottingScope"]; // prevent collision damage
_direction = getDir _unit; [QEGVAR(common,fixCollision), _unit] call CBA_fnc_localEvent;
_position = (getPosASL _unit) vectorAdd [0.8 * sin(_direction), 0.8 * cos(_direction), 0.02];
_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 setDir _direction;
_spottingScope setPosASL _position; _spottingScope setPosASL _position;
if ((getPosATL _spottingScope select 2) - (getPos _spottingScope select 2) < 1E-5) then { _spottingScope setVectorUp _vectorUp;
_spottingScope setVectorUp (surfaceNormal (position _spottingScope)); [QEGVAR(common,fixPosition), _spottingScope, _spottingScope] call CBA_fnc_targetEvent;
}; [QEGVAR(common,fixFloating), _spottingScope, _spottingScope] call CBA_fnc_targetEvent;
_unit reveal _spottingScope; _unit reveal _spottingScope;
}, [_unit], 1, 0] call CBA_fnc_waitAndExecute; }, [_unit], 1, 0] call CBA_fnc_waitAndExecute;