From 09461d94ef7f75c852ad8b7ad57b411f32234689 Mon Sep 17 00:00:00 2001 From: esteldunedain Date: Mon, 6 Apr 2015 18:10:17 -0300 Subject: [PATCH] Rewritten changeProjectileDirection --- .../fnc_changeProjectileDirection.sqf | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/addons/common/functions/fnc_changeProjectileDirection.sqf b/addons/common/functions/fnc_changeProjectileDirection.sqf index 85dce2f194..2cb37650b8 100644 --- a/addons/common/functions/fnc_changeProjectileDirection.sqf +++ b/addons/common/functions/fnc_changeProjectileDirection.sqf @@ -29,31 +29,25 @@ _adjustSpeed = if (count _this > 3) then { ["CPD", [_fnc_scriptNameParent, _adjustDir, _adjustUp, _adjustSpeed], nil, false] call FUNC(log); // get old direction vector -_vdir = vectorDir _projectile; +_vdir = vectorNormalized velocity _projectile; // get azimuth and inclination and apply corrections _dir = (_vdir select 0) atan2 (_vdir select 1) + _adjustDir; -_up = sqrt ((_vdir select 1) ^ 2 + (_vdir select 0) ^ 2) atan2 - (_vdir select 2) + _adjustUp; +_up = asin (_vdir select 2) + _adjustUp; // get new direction vector (this is a unit vector) _vdir = [ - sin _dir * sin _up, - cos _dir * sin _up, - - cos _up + sin _dir * cos _up, + cos _dir * cos _up, + sin _up ]; // get best up vector -_l = sqrt ((_vdir select 0) ^ 2 + (_vdir select 1) ^ 2); if (_l == 0) then {diag_log text format ["[ACE] ERROR: %1, %2, %3, %4, %5, %6, %7", _projectile, _adjustDir, _adjustUp, vectorDir _projectile, _vdir, _dir, _up]}; -_r = -(_vdir select 2) / _l; - -_vup = [ - (_vdir select 0) * _r, - (_vdir select 1) * _r, - _l -]; +_vlat = vectorNormalized (_vdir vectorCrossProduct [0,0,1]); +_vup = _vlat vectorCrossProduct _vdir; // get new speed vector. Keep total speed, but change to new direction. Yay for vector commands. -_vel = _vdir vectorMultiply _adjustSpeed + vectorMagnitude velocity _projectile; +_vel = _vdir vectorMultiply (_adjustSpeed + vectorMagnitude velocity _projectile); // set projectile direction dir and up. Projectiles are long objects, especially with tracers, so it would look dumb otherwise. _projectile setVectorDirAndUp [_vdir, _vup];