Fix dragging sending objects to random location

attachTo seems to have weird getpos results for a few frames.
also don't show mouse wheel option for carrying man
and always use 0 offset for dragging man
This commit is contained in:
PabstMirror 2016-01-28 17:11:05 -06:00
parent d9eafbdf0f
commit 3f1d6ffeb7
4 changed files with 25 additions and 6 deletions

View File

@ -57,10 +57,14 @@ _unit setVariable [QGVAR(ReleaseActionID), [
] call EFUNC(common,addActionEventHandler)];
// show mouse hint
[localize LSTRING(Drop), "", localize LSTRING(LowerRaise)] call EFUNC(interaction,showMouseHint);
if (_target isKindOf "CAManBase") then {
[localize LSTRING(Drop), "", ""] call EFUNC(interaction,showMouseHint);
} else {
[localize LSTRING(Drop), "", localize LSTRING(LowerRaise)] call EFUNC(interaction,showMouseHint);
};
// check everything
[FUNC(carryObjectPFH), 0.5, [_unit, _target]] call CBA_fnc_addPerFrameHandler;
[FUNC(carryObjectPFH), 0.5, [_unit, _target, ACE_time]] call CBA_fnc_addPerFrameHandler;
// reset current dragging height.
GVAR(currentHeightChange) = 0;

View File

@ -6,6 +6,7 @@
* 0: ARGS <ARRAY>
* 0: Unit <OBJECT>
* 1: Target <OBJECT>
* 2: Start time <NUMBER>
* 1: PFEH Id <NUMBER>
*
* Return Value:
@ -23,7 +24,7 @@
#endif
params ["_args", "_idPFH"];
_args params ["_unit","_target"];
_args params ["_unit","_target", "_startTime"];
if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {
TRACE_2("carry false",_unit,_target);
@ -33,6 +34,11 @@ if !(_unit getVariable [QGVAR(isCarrying), false]) exitWith {
// drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled))
if (!alive _target || {_unit distance _target > 10}) then {
TRACE_2("dead/distance",_unit,_target);
if ((_unit distance _target > 10) && {(ACE_time - _startTime) < 1}) exitWith {
//attachTo seems to have some kind of network delay and target can return an odd position durring the first few frames,
//so wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos)
TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,ACE_time);
};
[_unit, _target] call FUNC(dropObject_carry);
[_idPFH] call CBA_fnc_removePerFrameHandler;
};

View File

@ -25,10 +25,13 @@ private _direction = _target getVariable [QGVAR(dragDirection), 0];
// add height offset of model
private _offset = (_target modelToWorldVisual [0, 0, 0] select 2) - (_unit modelToWorldVisual [0, 0, 0] select 2);
if (_target isKindOf "CAManBase") then {
_offset = 0;
};
_position = _position vectorAdd [0, 0, _offset];
// attach object
TRACE_3("attaching",_position,_offset,_direction);
_target attachTo [_unit, _position];
["setDir", _target, [_target, _direction]] call EFUNC(common,targetEvent);
@ -50,7 +53,7 @@ _unit setVariable [QGVAR(ReleaseActionID), [
[localize LSTRING(Drop), ""] call EFUNC(interaction,showMouseHint);
// check everything
[FUNC(dragObjectPFH), 0.5, [_unit, _target]] call CBA_fnc_addPerFrameHandler;
[FUNC(dragObjectPFH), 0.5, [_unit, _target, ACE_time]] call CBA_fnc_addPerFrameHandler;
// reset current dragging height.
GVAR(currentHeightChange) = 0;

View File

@ -6,6 +6,7 @@
* 0: ARGS <ARRAY>
* 0: Unit <OBJECT>
* 1: Target <OBJECT>
* 2: Start time <NUMBER>
* 1: PFEH Id <NUMBER>
*
* Return Value:
@ -23,7 +24,7 @@
#endif
params ["_args", "_idPFH"];
_args params ["_unit", "_target"];
_args params ["_unit","_target", "_startTime"];
if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {
TRACE_2("drag false",_unit,_target);
@ -33,6 +34,11 @@ if !(_unit getVariable [QGVAR(isDragging), false]) exitWith {
// drop if the crate is destroyed OR (target moved away from carrier (weapon disasembled))
if (!alive _target || {_unit distance _target > 10}) then {
TRACE_2("dead/distance",_unit,_target);
if ((_unit distance _target > 10) && {(ACE_time - _startTime) < 1}) exitWith {
//attachTo seems to have some kind of network delay and target can return an odd position durring the first few frames,
//so wait a full second to exit if out of range (this is critical as we would otherwise detach and set it's pos to weird pos)
TRACE_3("ignoring bad distance at start",_unit distance _target,_startTime,ACE_time);
};
[_unit, _target] call FUNC(dropObject);
[_idPFH] call CBA_fnc_removePerFrameHandler;
};