Jump to content
Sign in to follow this  
kyfohatl

How to create an AA rocket that takes down your chopper?

Recommended Posts

Just when the player thinks the mission has ended and the allied transport chopper is landing to pick him and his squad up, an AA rockets hits the chopper (so now the player has to get back on foot). Currently I am using a unit called "enemyAA" and the script:

waitUntil {chopper distance enemyAA < 650};
enemyAA selectWeapon "Stinger";
sleep 1;
enemyAA doTarget chopper;
sleep 0.5;
enemyAA doFire chopper;

However, as the distance gets greater than the 650 meters, I've found that sometimes the AA soldier may not fire. So distance has to be 650 meters or less, and the AA soldier has to be in a reletively clrear spot (no trees or buildings blocking his view) according to my tests. This puts the exposed AA soldier in the danger of being spotted and killed by the player.

So, instead, is there a way to create a rocket somewhere (without a visible in-game source like an AA soldier), that hits the player chopper?

Thanks in advance for any help.

Share this post


Link to post
Share on other sites

I was going to suggest using the guided missile trick from ArmA2 to fake it, but seems that doesn't work too well with flying targets. Launches fine, flies fine (though smoke only lasts a few hundred meters) but when it gets into range it keeps setPosing really stupidly till it finally hits. :)

Share this post


Link to post
Share on other sites
I was going to suggest using the guided missile trick from ArmA2 to fake it, but seems that doesn't work too well with flying targets. Launches fine, flies fine (though smoke only lasts a few hundred meters) but when it gets into range it keeps setPosing really stupidly till it finally hits. :)

Thanks man, the line,"_missile = _missileType createVehicle _missileStart;" is what I was looking for. So here's my version of the script (a lot shorter, less flexible and not very well done) for a flyign target:

private ["_markerPos", "_missilePos", "_missile", "_targetX", "_targetY", "_targetZ"];

// creating the missile
_markerPos = getMarkerPos "Start";
_missilePos = [_markerPos select 0, _markerPos select 1, 500];
hint format ['Initiating'];
_missile = "M_Stinger_AA" createVehicle _missilePos;

// The missile continues to move towards the target by readjusting X,Y and Z values every loop
while {alive _missile} do {

_targetX = (getPos chopper) select 0;
_targetY = (getPos chopper) select 1;
_targetZ = (getPos chopper) select 2;

if (_missilePos select 0 > _targetX) then {
_missilePos = [(_missilePos select 0) -1, _missilePos select 1, _missilePos select 2];
} else {
_missilePos = [(_missilePos select 0) +1, _missilePos select 1, _missilePos select 2];
};


if (_missilePos select 1 > _targetY) then {
_missilePos = [_missilePos select 0, (_missilePos select 1) -1, _missilePos select 2];
} else {
_missilePos = [_missilePos select 0, (_missilePos select 1) +1, _missilePos select 2];
};


if (_missilePos select 2 > _targetZ) then {
_missilePos = [_missilePos select 0, _missilePos select 1, (_missilePos select 2) -1];
} else {
_missilePos = [_missilePos select 0, _missilePos select 1, (_missilePos select 2) +1];
};

_missile setPos _missilePos;
sleep 0.005;
};

Now this works fine for a ground target, but for an air target, just like you said, the missile path is retarded. The smoke goes backwards (in opposite direction) whilst the missile travels forward towards the chopper. And the smoke only lasts a very short time. Even when I add the line: (right at the end, before the end of the "While" statement)

if (_missile distance chopper < 5) then {_missile setpos (getPos chopper);};

The wierd missile path still remains (it get even wierder).

One more problem: The missile approaches the target backwards; that is, the front point (or nose) of the missile is pointing away from the chopper which makes the scene look really awkward. How can I keep the front point of the missile pointing towards the chopper at all times?

By the way, really nice website. The general set out just looks very neat. It has been very useful :)

Thanks

Edited by kyfohatl

Share this post


Link to post
Share on other sites

I tweaked this script 2 or 3 weeks ago so that it would hit flying jets correctly. The part that messes it up is this:

if (_missile distance _target > (_missileSpeed / 20)) then

I simply removed the entire outer if-then, and left what was inside it. The problem is that as the missile closes in on the target, the distances keep shifting back and forth and the missile would act all sorts of weird. This way it won't care about the distance and simply hit the target.

Share this post


Link to post
Share on other sites

@AZCoder: Ok, thanks, will remove it when using the script. However, I have a bit of trouble as Kylania's script (on his website, accesed by the link he provided in this thread) is a little too complicated for me to understand. I don't need the laser guided stuff, as the player has nothing to do with controlling the missile. A missile simply "pops out of nowhere" and hits the chopper that is about to pick up the player. Could anyone guide me on changing this script so that the "laser guided" stuff is removed?

By the way I've given up on my own script. It doesn't work very well.

Thanks

Edited by kyfohatl

Share this post


Link to post
Share on other sites

you should be able to attatch an invisible laser target to the incomming chopper, if a laser target is needed.

Share this post


Link to post
Share on other sites

I have 3 or 4 versions of it right now. This one will accelerate the missile from an initial speed to a max speed. I did that to try and make the missile more visible at first, although I think the result is minimal at best.

It's been tested against the MiG-15 from a ground unit's position, with both the MiG flying away, and the other flying toward. In the latter case, the missile does a really fast turn and nails the MiG.

To call it:

[_firingUnit, _target, "M_Igla_AA", 300] execVM "testMissile.sqf";

Where missile type is obvious, and 300 is the starting speed. Max speed is 600 and its hard coded just because I haven't felt like making in variable.

This is the missile script. And it was derived from Kylania's script several weeks ago:

private ["_firer","_velocityX", "_velocityY", "_velocityZ", "_target","_missileSpeed","_maxVeloc","_primaryTarget","_missileStart","_missileType"];

_firer  			= _this select 0;
_primaryTarget 	= _this select 1;
_missileStart 		= [(getPos _firer select 0) - 1, (getPos _firer select 1) + 2, (getPos _firer select 2) + 1];
_missileType 		= _this select 2;
_missileSpeed 	= _this select 3;
_maxVeloc 		= 600;

if (_missileSpeed > _maxVeloc) then { _missileSpeed = _maxVeloc; };

_perSecondChecks = 25; //direction checks per second
_getPrimaryTarget = {if (typeName _primaryTarget == typename {}) then {call _primaryTarget} else {_primaryTarget}};
_target = call _getPrimaryTarget;

_missile = _missileType createVehicle _missileStart;
_missile setPos _missileStart;
_missile setDir (getDir _firer);

//procedure for guiding the missile
_homeMissile = 
{
if (_missileSpeed < _maxVeloc) then { _missileSpeed = _missileSpeed + 10; };
_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;

[_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;

Share this post


Link to post
Share on other sites

Excuse me for being thick, my ability to understand code is sadly lacking. How would you go about setting the above script up in terms of objects in the editor? I could really use something like this :)

Share this post


Link to post
Share on other sites

name a trigger missilestart and place the following line in the on act

null = [missilestart, targ1, "M_Igla_AA", 300] execVM "testMissile.sqf";

Name the target targ1 and set the trigger to fire when you require.

Share this post


Link to post
Share on other sites

Seems like the simple thing is just to make the AA soldier invisible with 'hideobject this,' and invisible to AI with 'setcaptive true'

For the quick and dirty rube golderg way, consider even attaching the SAM to the chopper at a remove of 500m or so.

Share this post


Link to post
Share on other sites

Thanks F2k Sel, very much appreciated!

Like the idea Maturin but need something a little more consistent and guaranteed. In this case the AI would probably be a little but too hit and miss.

Thanks again guys :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×