fix collisions when releasing, fix crate fliping in buildings

This commit is contained in:
commy2 2015-03-17 11:44:41 +01:00
parent fef150cff2
commit 6d868d1bd1
7 changed files with 42 additions and 58 deletions

View File

@ -20,6 +20,7 @@ if (hasInterface) then {
};
}] call FUNC(addEventhandler);
["fixCollision", FUNC(fixCollision)] call FUNC(addEventhandler);
["fixPosition", FUNC(fixPosition)] call FUNC(addEventhandler);
// hack to get PFH to work in briefing

View File

@ -55,7 +55,7 @@ PREP(execPersistentFnc);
PREP(execRemoteFnc);
PREP(executePersistent);
PREP(filter);
PREP(fixCollisions);
PREP(fixCollision);
PREP(fixLoweredRifleAnimation);
PREP(fixPosition);
PREP(getAllDefinedSetVariables);

View File

@ -0,0 +1,21 @@
/*
* Author: commy2
* Attempt to fix physx collisions causing unreasonable impact forces and damage.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* Nothing
*
*/
#include "script_component.hpp"
// allowDamage requires local object
if (!local _this) exitWith {};
// prevent collision damage, @todo allowDamage API
_this allowDamage false;
// re-allow damage after 2 seconds
[{_this allowDamage true}, _this, 2, 0] call EFUNC(common,waitAndExecute);

View File

@ -1,55 +0,0 @@
/*
* Author: commy2
* Attempt to fix physx collisions causing unreasonable impact forces and damage.
*
* Arguments:
* 0: Object <OBJECT>
*
* Return Value:
* Nothing
*
*/
#include "script_component.hpp"
private "_object";
_object = _this select 0;
if (!local _object) exitWith {};
// ignore collision damage
_object setVariable [QGVAR(fixCollisionsDamage), damage _object];
private ["_ehID", "_vectorDirAndUp"];
_ehID = _object addEventHandler ["HandleDamage", {
if (isNull (_this select 3)) exitWith {
(_this select 0) getVariable [QGVAR(fixCollisionsDamage), 0];
};
(_this select 0) setVariable [QGVAR(fixCollisionsDamage), _this select 2];
_this select 2
}];
_vectorDirAndUp = [vectorDir _object, vectorUp _object];
[{
private ["_object", "_ehID", "_vectorDirAndUp", "_timeOut"];
_object = _this select 0 select 0;
_ehID = _this select 0 select 1;
_vectorDirAndUp = _this select 0 select 2;
_timeOut = _this select 0 select 3;
// adjust vector to prevent fliping
_object setVectorDirAndUp _vectorDirAndUp;systemChat str damage _object;//
if (time > _timeOut) exitWith {
_object removeEventHandler ["HandleDamage", _ehID];hint str time;//
[_this select 1] call CBA_fnc_removePerFrameHandler;
};
}, 0, [_object, _ehID, _vectorDirAndUp, time + 2]] call CBA_fnc_addPerFrameHandler;

View File

@ -8,6 +8,7 @@ PREP(dragObject);
PREP(dragObjectPFH);
PREP(dropObject);
PREP(initObject);
PREP(isObjectOnObject);
PREP(setDraggable);
PREP(startDrag);
PREP(startDragPFH);

View File

@ -20,14 +20,24 @@ _target = _this select 1;
// remove scroll wheel action
_unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]);
private "_inBuilding";
_inBuilding = [_unit] call FUNC(isObjectOnObject);
// play release animation
_unit playAction "released";
// release object
[_target] call EFUNC(common,fixCollisions);//"fixCollision"
// prevent collision damage
["fixCollision", _target, _target] call EFUNC(common,targetEvent);
// release object
detach _target;
// prevent object from flipping inside buildings
if (_inBuilding) then {
_target setPosASL (getPosASL _target vectorAdd [0, 0, 0.05]);
};
_unit setVariable [QGVAR(isDragging), false, true];
_unit setVariable [QGVAR(draggedObject), objNull, true];

View File

@ -0,0 +1,6 @@
// by commy2
private "_object";
_object = _this select 0;
(getPosATL _object select 2) - (getPos _object select 2) > 1E-5