ACE3/addons/dragging/functions/fnc_handleScrollWheel.sqf

52 lines
1.6 KiB
Plaintext
Raw Normal View History

/*
* Author: L-H, commy2
* Handles raising and lowering the dragged weapon to be able to place it on top of objects.
*
2015-08-09 12:53:13 +00:00
* Arguments:
* 0: Scroll amount <NUMBER>
*
2015-08-09 12:53:13 +00:00
* Return Value:
* Handled or not. <BOOL>
*
2016-01-28 18:52:53 +00:00
* Example:
* [0.1] call ace_dragging_fnc_handleScrollWheel;
*
2015-08-09 12:53:13 +00:00
* Public: No
*/
#include "script_component.hpp"
2015-08-09 12:53:13 +00:00
params ["_scrollAmount"];
2016-01-28 18:52:53 +00:00
private _unit = ACE_player;
// EH is always assigned. Exit and don't overwrite input if not carrying
if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {false};
// move carried item 15 cm per scroll interval
_scrollAmount = _scrollAmount * 0.15;
2016-01-28 18:52:53 +00:00
private _carriedItem = _unit getVariable [QGVAR(carriedObject), objNull];
2015-03-25 12:32:59 +00:00
//disabled for persons
if (_carriedItem isKindOf "CAManBase") exitWith {false};
2016-01-28 18:52:53 +00:00
private _position = getPosATL _carriedItem;
private _maxHeight = (_unit modelToWorldVisual [0,0,0]) select 2;
_position set [2, ((_position select 2) + _scrollAmount min (_maxHeight + 1.5)) max _maxHeight];
// move up/down object and reattach at current position
detach _carriedItem;
// Uses this method of selecting position because setPosATL did not have immediate effect
private _positionChange = _position vectorDiff (getPosATL _carriedItem);
private _selectionPosition = _unit worldToModel (ASLtoAGL getPosWorld _carriedItem);
_selectionPosition = _selectionPosition vectorAdd _positionChange;
_carriedItem attachTo [_unit, _selectionPosition];
//reset the carry direction
private _direction = _carriedItem getVariable [QGVAR(carryDirection), 0];
[QEGVAR(common,setDir), [_carriedItem, _direction], _carriedItem] call CBA_fnc_targetEvent;
true