The script, for now, is finished. I did not implement any advanced methods of calculating lead, and rather allowed the user to specify lateral and height offsets. I believe this is enough and only a minor inconvenience. Soon, I will make a similar version that uses a specific coordinate starting position instead of relative coordinates.
Here we are...
// "Missile Generator (Relative)" by DrBobcat
// [target,"type",x,y,z,lateralOffset,heightOffset,proximityBool,proximityDistance] execvm "DRB_MissileR.sqf";
// Much thanks goes out to the ArmA/OFP editing community!
_target = _this select 0;
_type = _this select 1;
_xPos = _this select 2;
_yPos = _this select 3;
_zPos = _this select 4;
_lOff = _this select 5;
_hOff = _this select 6;
_prox = _this select 7;
_pDis = _this select 8;
_burst = objNull;
_round = _type createvehicle [0,0,1000];
if (_prox) then {_burst = "Bomb" createVehicle [0,0,1005];};
_round setPos [(getposASL _target select 0) + _xPos, (getposASL _target select 1) + _yPos, (getposASL _target select 2) + _zPos];
while {!(isNull _round)} do
{
if ((_round distance _target) <= _pDis) exitWith
{
_round setVelocity [0,0,0];
{_x setPos (getpos _round)} forEach [_burst,_round];
_burst setDammage 1;
sleep 0.1;
{deleteVehicle _x} forEach [_burst,_round];
};
_lPosX = ((getPosASL _target select 0) + (_lOff * (sin (getDir _target))));
_lPosY = ((getPosASL _target select 1) + (_lOff * (cos (getDir _target))));
_lAng = ((_lPosX - (getposASL _round select 0)) atan2 (_lPosY - (getposASL _round select 1)));
_round setVectorDir [sin _lAng, cos _lAng, vectorDir _round select 2];
if (_xPos != 0) then
{
_zAng = (((_lPosX) - (getposASL _round select 0)) atan2 (((getposASL _target select 2) + _hOff) - (getposASL _round select 2)));
_round setVectorUp [cos _zAng, 0, -(sin _zAng)];
} else
{
_zAng = (((_lPosY) - (getposASL _round select 1)) atan2 (((getposASL _target select 2) + _hOff) - (getposASL _round select 2)));
_round setVectorUp [0, cos _zAng, -(sin _zAng)];
};
sleep 0.01;
};
Again, thanks for all the help. If anyone notices any glaring flaws that I may have overlooked, please do speak up!
- dRb