Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the placement of spotting scopes on slopes #3919

Merged
merged 1 commit into from
Jun 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions addons/spottingscope/functions/fnc_place.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;