From dac399963eab24e23889126a5597e846db93d107 Mon Sep 17 00:00:00 2001 From: LinkIsGrim Date: Wed, 3 Jan 2024 08:45:10 -0300 Subject: [PATCH] prevent casings from sinking below the terrain --- addons/casings/functions/fnc_createCasing.sqf | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/casings/functions/fnc_createCasing.sqf b/addons/casings/functions/fnc_createCasing.sqf index 22347d36a7..f619c0e1b8 100644 --- a/addons/casings/functions/fnc_createCasing.sqf +++ b/addons/casings/functions/fnc_createCasing.sqf @@ -48,7 +48,7 @@ if (isNil "_modelPath") then { if (_modelPath isEqualTo "") exitWith {}; -private _unitPos = getposASL _unit; +private _unitPos = getPosASL _unit; // Distant shooters don't produce as many cases if ((AGLToASL positionCameraToWorld [0,0,0]) vectorDistance _unitPos > 100 && {random 1 < 0.9}) exitWith {}; @@ -60,10 +60,14 @@ private _pos = _unitPos [ { - params ["_modelPath", "_pos"]; + params ["_modelPath", "_pos", "_unitPos"]; - private _lisPos = (lineIntersectsSurfaces [_pos, _pos vectorAdd [0,0,-1e11], objNull, objNull, true, 1, "ROADWAY", "FIRE"]) #0; - private _casing = createSimpleObject [_modelPath, (_lisPos #0 vectorAdd [0,0,0.005]), true]; + private _lisPos = (lineIntersectsSurfaces [_pos, _pos vectorAdd [0,0,-1e11], objNull, objNull, true, 1, "ROADWAY", "FIRE"]) select 0; + private _casingPos = (_lisPos select 0) vectorAdd [0,0,0.005]; + if (((ASLtoATL _casingPos) select 2) < 0) then { // prevent casings sinking into the terrain + _casingPos set [2, _unitPos select 2]; + }; + private _casing = createSimpleObject [_modelPath, _casingPos, true]; _casing setDir (random 360); _casing setVectorUp _lisPos #1; private _idx = GVAR(casings) pushBack _casing; @@ -72,6 +76,6 @@ private _pos = _unitPos deleteVehicle (GVAR(casings) deleteAt 0); }; }, - [_modelPath,_pos], - 0.4 + [_modelPath, _pos, _unitPos], + 0.1 ] call CBA_fnc_waitAndExecute;