Guided Missile Call (Trigger/addAction)

1. Place Functions Module
2. Create a GameLogic and name it missilestart and place it where you want your missiles coming from. (500m up seemed pretty awesome: this setPos [getPos this select 0, getPos this select 1, 500]) Looks best when it’s within 1000m of the player.
3. Call it from the radio or addAction with the following code:

nul=[laserTarget player, getpos missilestart,"M_Ch29_AT",200] execvm "launchmissile.sqf"

4. Use the script below with one small change from the original (in orange below). Basically if your laser it’s turned on you won’t get a missile.

_primaryTarget = _this select 0; //target for the missile
_missileStart = _this select 1; //position where te missile will be spawned
_missileType = _this select 2; //type of the missile
_missileSpeed = _this select 3; //speed of the missile
_defaultTargetPos = _this select 4; //default position where unguided missiles will fly [8340.718750,3074.914795,0];

if (isNull _primarytarget) exitWith {hintSilent "No Target Found!"};

_perSecondChecks = 25; //direction checks per second
_getPrimaryTarget = {if (typeName _primaryTarget == typename {}) then {call _primaryTarget} else {_primaryTarget}}; //code can be used for laser dots
_target = call _getPrimaryTarget;

_missile = _missileType createVehicle _missileStart;
_missile setPos _missileStart;

//secondary target used for random trajectory when laser designator is turned off prematurily
_secondaryTarget = "HeliHEmpty" createVehicle _defaultTargetPos;
_secondaryTarget setPos _defaultTargetPos;

_guidedRandomly = FALSE;

//procedure for guiding the missile
_homeMissile = {

//here we switch to secondary target at random position if the laser dot no longer exists
//if the designator is turned on again, the missile will return to it's original target (providing it hadn't flown too far)
private ["_velocityX", "_velocityY", "_velocityZ", "_target"];
_target = _secondaryTarget;
if (!(_guidedRandomly) && _missile distance _target > _missileSpeed * 1.5) then {
_guidedRandomly = TRUE;
_target = _secondaryTarget;
_dispersion = (_missile distance _defaultTargetPos) / 20;
_dispersionMin = _dispersion / 10;
_target setPos [(_defaultTargetPos select 0) + _dispersionMin - (_dispersion / 2) + random _dispersion, (_defaultTargetPos select 1) + _dispersionMin - (_dispersion / 2) + random _dispersion, 0];
if (!(isNull (call _getPrimaryTarget))) then {_target = call _getPrimaryTarget; _defaultTargetPos = position _target; _guidedRandomly = FALSE};

//altering the direction, pitch and trajectory of the missile
if (_missile distance _target > (_missileSpeed / 20)) then {
_travelTime = (_target distance _missile) / _missileSpeed;
_steps = floor (_travelTime * _perSecondChecks);

_relDirHor = [_missile, _target] call BIS_fnc_DirTo;
_missile setDir _relDirHor;

_relDirVer = asin ((((getPosASL _missile) select 2) - ((getPosASL _target) select 2)) / (_target distance _missile));
_relDirVer = (_relDirVer * -1);
[_missile, _relDirVer, 0] call BIS_fnc_setPitchBank;

_velocityX = (((getPosASL _target) select 0) - ((getPosASL _missile) select 0)) / _travelTime;
_velocityY = (((getPosASL _target) select 1) - ((getPosASL _missile) select 1)) / _travelTime;
_velocityZ = (((getPosASL _target) select 2) - ((getPosASL _missile) select 2)) / _travelTime;

//_defaultTargetPos = position _target;

[_velocityX, _velocityY, _velocityZ]

call _homeMissile;

//fuel burning should illuminate the landscape
_fireLight = "#lightpoint" createVehicle position _missile;
_fireLight setLightBrightness 0.5;
_fireLight setLightAmbient [1.0, 1.0, 1.0];
_fireLight setLightColor [1.0, 1.0, 1.0];
_fireLight lightAttachObject [_missile, [0, -0.5, 0]];

//missile flying
while {alive _missile} do {
_velocityForCheck = call _homeMissile;
if ({(typeName _x) == (typeName 0)} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck};
sleep (1 / _perSecondChecks)

deleteVehicle _fireLight;
deleteVehicle _secondaryTarget;

In testing it seemed as if the deftarget stuff wasn’t working at all, or if it was the distance was so small as to not matter, so I removed that part of the setup. Script seems to run fine.

It’s a little crazy how the missile will follow your target like a cat chasing a laser pen till she crashes into something!

I also made a demo mission for this example which includes:

  • 15 second reloading timer
  • Inability to call in a strike while reloading

To call this mission from an addAction rather than a Radio Trigger you’d change the script like this:

_primaryTarget = lasertarget (_this select 1); //target for the missile
_missileStart = getPos ((_this select 3) select 1); //position where te missile will be spawned
_missileType = (_this select 3) select 2; //type of the missile
_missileSpeed = (_this select 3) select 3; //speed of the missile
_defaultTargetPos = (_this select 3) select 4; //default position where unguided missiles

and call it like this:

this addAction["Fire Missile","launchMissile.sqf",[this, missilestart,"M_Hellfire_AT",200]];
  1. #1 by mia389 on November 4, 2010 - 9:38 PM

    I cant wait to try this out. This will give my USS Minnesota cruise missiles 🙂

  2. #2 by mia389 on November 4, 2010 - 9:52 PM

    Worked perfect! Thanks for example mission

  3. #3 by Anemia on November 14, 2010 - 6:11 AM

    the missle often crash in some trees or hills infront of the target by long range call’s

    any ideas how to fix it ?!

  4. #4 by Anemia on November 14, 2010 - 6:15 AM

    or maybe how to lift up the missle start point for a better flight path to the target

    • #5 by kylania on November 14, 2010 - 5:28 PM

      You can change the starting point of the missilestart GameLogic to change where the missile comes from. Also remember it follows the laser dot in essentially real time, so you have to hold the dot on the target for it to hit. If you move it around the missile will follow the dot! Kinda fun really, especially if you slow it down.

      • #6 by Anemia on November 15, 2010 - 9:40 AM

        I have changed the Class of the Misslie to a Maverick and maybe its only my impression but it seems to work better. Crashes with Trees infront of the targets still happens … but i think the dive innfront of a target is better now.

        Once i pointed a Radiotower with my dot and the misslie flys more the twenty circels around it 😉

Comments are closed.