-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nlaw - Update to use Missile Guidance Framework (#10034)
- Loading branch information
1 parent
2c4c7c2
commit a1cafef
Showing
10 changed files
with
207 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ PREP(attackProfile); | |
PREP(keyDown); | ||
PREP(onFired); | ||
PREP(seeker); | ||
PREP(navigation); | ||
PREP(navigation_onFired); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: tcvm | ||
* Attempts to hold angle as fed to by seeker. Does so with a simple proportional controller | ||
* | ||
* Arguments: | ||
* Guidance Arg Array <ARRAY> | ||
* | ||
* Return Value: | ||
* Commanded acceleration normal to LOS in world space <ARRAY> | ||
* | ||
* Example: | ||
* [] call ace_missileguidance_fnc_navigationType_line | ||
* | ||
* Public: No | ||
*/ | ||
// arbitrary constant | ||
#define PROPORTIONALITY_CONSTANT 20 | ||
params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos", "_targetData", "_navigationParams"]; | ||
_args params ["_firedEH"]; | ||
_firedEH params ["","","","","","","_projectile"]; | ||
|
||
_navigationParams params ["_yawChange", "_pitchChange", "_lastPitch", "_lastYaw", "_initialPitch", "_pitchUp", "_lastYawRateDifference"]; | ||
|
||
// for some reason we need to multiply this. I don't know why, but it just works | ||
_pitchChange = _pitchChange * 1.5; | ||
_yawChange = _yawChange * 1.5; | ||
|
||
((velocity _projectile) call CBA_fnc_vect2polar) params ["", "_currentYaw", "_currentPitch"]; | ||
|
||
private _pitchRate = if (_timestep == 0) then { | ||
0 | ||
} else { | ||
(_currentPitch - _lastPitch) / _timestep | ||
}; | ||
_navigationParams set [2, _currentPitch]; | ||
|
||
private _pitchModifier = if (_pitchChange == 0) then { | ||
1 | ||
} else { | ||
abs (_pitchRate / _pitchChange) | ||
}; | ||
private _desiredPitchChange = (_pitchChange - _pitchRate) * PROPORTIONALITY_CONSTANT * _pitchModifier; | ||
_desiredPitchChange = _desiredPitchChange + _pitchUp * (_initialPitch - _currentPitch) * PROPORTIONALITY_CONSTANT * _pitchModifier; | ||
|
||
private _yawRate = if (_timestep == 0) then { | ||
0 | ||
} else { | ||
(_currentYaw - _lastYaw) / _timestep | ||
}; | ||
_navigationParams set [3, _currentYaw]; | ||
|
||
private _yawModifier = if (_yawChange == 0) then { | ||
1 | ||
} else { | ||
abs (_yawRate / _yawChange) | ||
}; | ||
|
||
private _yawRateDifference = _yawChange - _yawRate; | ||
private _yawChangeDerivative = if (_timestep == 0) then { | ||
0 | ||
} else { | ||
(_yawRateDifference - _lastYawRateDifference) / _timestep | ||
}; | ||
_navigationParams set [6, _yawRateDifference]; | ||
|
||
private _desiredYawChange = _yawRateDifference * PROPORTIONALITY_CONSTANT + _yawRateDifference * 2; | ||
|
||
#ifdef DRAW_NLAW_INFO | ||
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], ASLtoAGL getPosASLVisual _projectile, 0.75, 0.75, 0, format ["dP [%1] dY: [%2]", _desiredPitchChange, _desiredYawChange], 1, 0.025, "TahomaB"]; | ||
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,1,1], [0, 0, 1] vectorAdd ASLtoAGL getPosASLVisual _projectile, 0.75, 0.75, 0, format ["pitch proportional [%1] yaw proportional [%2]", _pitchModifier, _yawModifier], 1, 0.025, "TahomaB"]; | ||
#endif | ||
|
||
TRACE_4("nlaw pitch/yaw info",_currentPitch,_lastPitch,_currentYaw,_lastYaw); | ||
TRACE_6("nlaw navigation",_yawChange,_desiredYawChange,_pitchChange,_desiredPitchChange,_yawRate,_pitchRate); | ||
|
||
_projectile vectorModelToWorldVisual [_yawChange + _desiredYawChange, 0, _pitchChange + _desiredPitchChange] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: PabstMirror | ||
* Sets up missile guidance state arrays (called from missileGuidance's onFired). | ||
* | ||
* Arguments: | ||
* Guidance Arg Array <ARRAY> | ||
* | ||
* Return Value: | ||
* Navigation Parameters <ARRAY> | ||
* | ||
* Example: | ||
* [] call ace_nlaw_fnc_onFired | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"]; | ||
_firedEH params ["_shooter","","","","","","_projectile"]; | ||
_launchParams params ["","_targetLaunchParams","","_attackProfile"]; | ||
_targetLaunchParams params ["_target"]; | ||
_stateParams params ["", "", "", "", "_navigationParams"]; | ||
|
||
// Reset _launchPos origin as projectile's height instead of player's foot | ||
_targetLaunchParams set [2, getPosASL _projectile]; | ||
|
||
// Get state params: | ||
TRACE_3("start of attack profile",_attackProfile,_shooter,vectorDir _projectile); | ||
|
||
private _firedLOS = _shooter weaponDirection (currentWeapon _shooter); | ||
private _yawChange = 0; | ||
private _pitchChange = 0; | ||
|
||
if (_shooter == ACE_player) then { | ||
TRACE_2("isPlayer",GVAR(yawChange),GVAR(pitchChange)); | ||
_yawChange = GVAR(yawChange); | ||
_pitchChange = GVAR(pitchChange); | ||
TRACE_1("los check",_firedLOS call CBA_fnc_vect2Polar); | ||
} else { | ||
if ((!isNil "_target") && {!isNull _target}) then { | ||
_firedLOS = (getPosASL _projectile) vectorFromTo (aimPos _target); | ||
(((eyePos _shooter) vectorFromTo (aimPos _target)) call CBA_fnc_vect2Polar) params ["", "_startYaw", "_startPitch"]; | ||
// Add some random error to AI's velocity prediction: | ||
private _random = random [(_shooter skillFinal "aimingAccuracy") min 0.9, 1, 2-((_shooter skillFinal "aimingAccuracy") min 0.9)]; | ||
(((eyePos _shooter) vectorFromTo ((aimPos _target) vectorAdd ((velocity _target) vectorMultiply (_random)))) call CBA_fnc_vect2Polar) params ["", "_predictedYaw", "_predictedPitch"]; | ||
_yawChange = ([_predictedYaw - _startYaw] call CBA_fnc_simplifyAngle180); | ||
_pitchChange = ([_predictedPitch - _startPitch] call CBA_fnc_simplifyAngle180); | ||
TRACE_1("AI",_target); | ||
} else { | ||
TRACE_1("AI - no target",_target); | ||
}; | ||
}; | ||
|
||
// Limit Max Deflection | ||
//_yawChange = -10 max _yawChange min 10; | ||
//_pitchChange = -10 max _pitchChange min 10; | ||
|
||
((velocity _projectile) call CBA_fnc_vect2polar) params ["", "_currentYaw", "_currentPitch"]; | ||
((ACE_player weaponDirection (currentWeapon ACE_player)) call CBA_fnc_vect2Polar) params ["", "_yaw", "_pitch"]; | ||
|
||
TRACE_5("attackProfileStateParams",_firedLOS,_yawChange,_pitchChange,_currentPitch,_currentYaw); | ||
_navigationParams set [0, _yawChange]; | ||
_navigationParams set [1, _pitchChange]; | ||
_navigationParams set [2, _currentPitch]; // last pitch | ||
_navigationParams set [3, _currentYaw]; // last yaw | ||
_navigationParams set [4, _pitch]; // initial pitch | ||
_navigationParams set [5, 0]; // whether or not to zero out the pitch | ||
_navigationParams set [6, 0]; | ||
_navigationParams | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters