From f5b316176cca740c6eb6a4e06ba7c57d0601d616 Mon Sep 17 00:00:00 2001 From: Brandon Danyluk Date: Sat, 1 May 2021 20:19:22 -0600 Subject: [PATCH] Add paremter to allow weathervaning Weapons usually tend toward the velocity vector due to aerodynamics - calculate side slip and use calculation to do this --- addons/gbu/CfgAmmo.hpp | 1 + .../functions/fnc_guidancePFH.sqf | 18 +++++++++++++++--- .../missileguidance/functions/fnc_onFired.sqf | 6 +++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/addons/gbu/CfgAmmo.hpp b/addons/gbu/CfgAmmo.hpp index 51dc8134d2..1f751d0934 100644 --- a/addons/gbu/CfgAmmo.hpp +++ b/addons/gbu/CfgAmmo.hpp @@ -10,6 +10,7 @@ class CfgAmmo { yawRate = 5; bangBangGuidance = 1; + stabilityCoefficient = 0.4; // how much this projectile likes to "weathervane" (keep direction toward velocity) canVanillaLock = 0; // Can this default vanilla lock? Only applicable to non-cadet mode diff --git a/addons/missileguidance/functions/fnc_guidancePFH.sqf b/addons/missileguidance/functions/fnc_guidancePFH.sqf index fb843528c0..b1c17e92da 100644 --- a/addons/missileguidance/functions/fnc_guidancePFH.sqf +++ b/addons/missileguidance/functions/fnc_guidancePFH.sqf @@ -32,7 +32,7 @@ if (!alive _projectile || isNull _projectile || isNull _shooter) exitWith { private _timestep = diag_deltaTime * accTime; -_flightParams params ["_pitchRate", "_yawRate", "_isBangBangGuidance"]; +_flightParams params ["_pitchRate", "_yawRate", "_isBangBangGuidance", "_stabilityCoefficient"]; // Run seeker function: private _seekerTargetPos = [[0,0,0], _args, _seekerStateParams, _lastKnownPosState, _timestep] call FUNC(doSeekerSearch); @@ -110,8 +110,18 @@ if ((_pitchRate != 0 || {_yawRate != 0}) && {_profileAdjustedTargetPos isNotEqua }; TRACE_9("pitch/yaw/roll",_pitch,_yaw,_roll,_yawChange,_pitchChange,_pitchRate,_yawRate,_clampedPitch,_clampedYaw); - _pitch = _pitch + _clampedPitch * _timestep; - _yaw = _yaw + _clampedYaw * _timestep; + // directional stability + private _localVelocity = _projectile vectorWorldToModelVisual (velocity _projectile); + + private _velocityAngleYaw = (_localVelocity#0) atan2 (_localVelocity#1); + private _velocityAnglePitch = (_localVelocity#2) atan2 (_localVelocity#1); + + // bastardized version of direction stability https://en.wikipedia.org/wiki/Directional_stability#Steering_forces + private _forceYaw = _stabilityCoefficient * _velocityAngleYaw + _clampedYaw; + private _forcePitch = _stabilityCoefficient * _velocityAnglePitch + _clampedPitch; + + _pitch = _pitch + _forcePitch * _timestep; + _yaw = _yaw + _forceYaw * _timestep; TRACE_3("new pitch/yaw/roll",_pitch,_yaw,_roll); @@ -184,6 +194,8 @@ if (GVAR(debug_drawGuidanceInfo)) then { _PS setParticleParams [["\A3\Data_f\cl_basic", 8, 3, 1], "", "Billboard", 1, 3.0141, [0, 0, 2], [0, 0, 0], 1, 1.275, 1, 0, [1, 1], [[1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1]], [1], 1, 0, "", "", nil]; _PS setDropInterval 1.0; }; + + drawLine3D [ASLtoAGL _projectilePos, (ASLtoAGL _projectilePos) vectorAdd velocity _projectile, [1, 1, 1, 1]]; }; _stateParams set [0, diag_tickTime]; diff --git a/addons/missileguidance/functions/fnc_onFired.sqf b/addons/missileguidance/functions/fnc_onFired.sqf index 3f85c9d587..37748df853 100644 --- a/addons/missileguidance/functions/fnc_onFired.sqf +++ b/addons/missileguidance/functions/fnc_onFired.sqf @@ -116,6 +116,9 @@ if (isNumber (_config >> "pitchRate")) then { _bangBang = 1 == getNumber (_config >> "bangBangGuidance"); }; +// How much this projectile likes to stay toward current velocity +private _stabilityCoefficient = getNumber (_config >> "stabilityCoefficient"); + private _navigationStateSubclass = _config >> "navigationStates"; private _states = getArray (_navigationStateSubclass >> "states"); @@ -148,7 +151,8 @@ private _args = [_this, [ _pitchRate, _yawRate, - _bangBang + _bangBang, + _stabilityCoefficient ], [ getNumber ( _config >> "seekerAngle" ),