Skip to content

Commit

Permalink
add cartridge ejection effect on repeat (#1158)
Browse files Browse the repository at this point in the history
* add cartridge effect on repeat

* optimize

* velocity one frame later to fix drawn position in frame 0

* update variable names
  • Loading branch information
commy2 authored Jun 15, 2019
1 parent cd8a239 commit 6a42995
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions addons/events/fnc_weaponEvents.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if (!_isEmpty || _onEmpty) then {
"_unit", "_weapon", "_muzzle", "_optic",
"_handAction", "_sound", "_soundSource",
"_expectedMagazineCount", "_time", "_delay",
"_triggerReleased"
"_triggerReleased", "_config"
];

// exit if unit switched weapon
Expand Down Expand Up @@ -126,11 +126,66 @@ if (!_isEmpty || _onEmpty) then {
_soundSource say3D _sound;
};

// eject cartidge on repeat
private _cartridgeType = getText (_config >> "cartridgeType");

if (_cartridgeType != "") then {
private _cartridgeEjectPosition = getArray (_config >> "cartridgeEjectPosition");
private _cartridgeEjectVelocity = getArray (_config >> "cartridgeEjectVelocity");
private _cartridgeEjectDelay = getNumber (_config >> "cartridgeEjectDelay");

if (_cartridgeEjectPosition isEqualTo []) then {
_cartridgeEjectPosition = [0,0,0];
};

if (_cartridgeEjectVelocity isEqualTo []) then {
_cartridgeEjectVelocity = [0,1,0];
};

[{
params ["_unit", "_weapon", "_cartridgeType", "_cartridgeEjectPosition", "_cartridgeEjectVelocity"];

private _pelvis = _unit modelToWorldVisualWorld (_unit selectionPosition "Pelvis");
private _camera = _unit modelToWorldVisualWorld (_unit selectionPosition "camera");
private _bodyUp = _pelvis vectorFromTo _camera;

private _weaponDir = _unit weaponDirection _weapon;
private _weaponLat = vectorNormalized (_weaponDir vectorCrossProduct _bodyUp);
private _weaponUp = _weaponLat vectorCrossProduct _weaponDir;

private _origin = _unit modelToWorldVisualWorld (_unit selectionPosition "proxy:\a3\characters_f\proxies\weapon.001");

private _position = _origin vectorAdd
(_weaponDir vectorMultiply _cartridgeEjectPosition#0) vectorAdd
(_weaponLat vectorMultiply _cartridgeEjectPosition#1) vectorAdd
(_weaponUp vectorMultiply _cartridgeEjectPosition#2);

private _cartridge = _cartridgeType createVehicleLocal ASLToAGL _position;

_cartridge setVectorDirAndUp [
vectorNormalized _weaponDir,
vectorNormalized _weaponUp
];

private _velocity = velocity _unit vectorAdd
(_weaponDir vectorMultiply _cartridgeEjectVelocity#0) vectorAdd
(_weaponLat vectorMultiply _cartridgeEjectVelocity#1) vectorAdd
(_weaponUp vectorMultiply _cartridgeEjectVelocity#2);

[{
params ["_cartridge", "_velocity"];
_cartridge setVelocity _velocity;
}, [_cartridge, _velocity]] call CBA_fnc_execNextFrame;
}, [
_unit, _weapon, _cartridgeType, _cartridgeEjectPosition, _cartridgeEjectVelocity
], _cartridgeEjectDelay] call CBA_fnc_waitAndExecute;
};

true // exit loop
}, {}, [
_unit, _weapon, _muzzle, _optic,
_handAction, _sound, call _fnc_soundSource,
_expectedMagazineCount, CBA_missionTime, _delay,
_triggerReleased
_triggerReleased, _config
]] call CBA_fnc_waitUntilAndExecute;
};

0 comments on commit 6a42995

Please sign in to comment.