From fef150cff2fa83a23c5f4f9e9e2e0fb2c174e83c Mon Sep 17 00:00:00 2001 From: commy2 Date: Tue, 17 Mar 2015 00:24:25 +0100 Subject: [PATCH] attempt to fix collisions --- addons/common/XEH_preInit.sqf | 1 + addons/common/functions/fnc_fixCollisions.sqf | 55 +++++++++++++++++++ addons/dragging/functions/fnc_dropObject.sqf | 2 + 3 files changed, 58 insertions(+) create mode 100644 addons/common/functions/fnc_fixCollisions.sqf diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index c822de6d47..a70014c25d 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -55,6 +55,7 @@ PREP(execPersistentFnc); PREP(execRemoteFnc); PREP(executePersistent); PREP(filter); +PREP(fixCollisions); PREP(fixLoweredRifleAnimation); PREP(fixPosition); PREP(getAllDefinedSetVariables); diff --git a/addons/common/functions/fnc_fixCollisions.sqf b/addons/common/functions/fnc_fixCollisions.sqf new file mode 100644 index 0000000000..2f4078bb1f --- /dev/null +++ b/addons/common/functions/fnc_fixCollisions.sqf @@ -0,0 +1,55 @@ +/* + * Author: commy2 + * Attempt to fix physx collisions causing unreasonable impact forces and damage. + * + * Arguments: + * 0: 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; diff --git a/addons/dragging/functions/fnc_dropObject.sqf b/addons/dragging/functions/fnc_dropObject.sqf index 35952af48e..dc850c6f00 100644 --- a/addons/dragging/functions/fnc_dropObject.sqf +++ b/addons/dragging/functions/fnc_dropObject.sqf @@ -24,6 +24,8 @@ _unit removeAction (_unit getVariable [QGVAR(ReleaseActionID), -1]); _unit playAction "released"; // release object +[_target] call EFUNC(common,fixCollisions);//"fixCollision" + detach _target; _unit setVariable [QGVAR(isDragging), false, true];