prevent casings from sinking below the terrain

This commit is contained in:
LinkIsGrim 2024-01-03 08:45:10 -03:00
parent dababe84b9
commit dac399963e

View File

@ -48,7 +48,7 @@ if (isNil "_modelPath") then {
if (_modelPath isEqualTo "") exitWith {}; if (_modelPath isEqualTo "") exitWith {};
private _unitPos = getposASL _unit; private _unitPos = getPosASL _unit;
// Distant shooters don't produce as many cases // Distant shooters don't produce as many cases
if ((AGLToASL positionCameraToWorld [0,0,0]) vectorDistance _unitPos > 100 && {random 1 < 0.9}) exitWith {}; 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 _lisPos = (lineIntersectsSurfaces [_pos, _pos vectorAdd [0,0,-1e11], objNull, objNull, true, 1, "ROADWAY", "FIRE"]) select 0;
private _casing = createSimpleObject [_modelPath, (_lisPos #0 vectorAdd [0,0,0.005]), true]; 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 setDir (random 360);
_casing setVectorUp _lisPos #1; _casing setVectorUp _lisPos #1;
private _idx = GVAR(casings) pushBack _casing; private _idx = GVAR(casings) pushBack _casing;
@ -72,6 +76,6 @@ private _pos = _unitPos
deleteVehicle (GVAR(casings) deleteAt 0); deleteVehicle (GVAR(casings) deleteAt 0);
}; };
}, },
[_modelPath,_pos], [_modelPath, _pos, _unitPos],
0.4 0.1
] call CBA_fnc_waitAndExecute; ] call CBA_fnc_waitAndExecute;