Barba-negra 117 Posted October 12, 2018 good morning, how are you guys? I'm asking for help because I'm not sure I know how to do it, I want to create a simple scripts for a missile that is fired from a ship called ship1 and that it moves up, and then moves to the direction of a goal already created called boat2, then I did something like this: cohete = createVehicle["Missile_AGM_02_F", barco1,[],50,"FLY"]; cohete setVelocity [0, 0, 20]; Sleep 0.5; cohete setVelocity [0, 0, 20]; Sleep 0.5; cohete setVelocity [0, 0, 20]; Sleep 0.5; cohete setVelocity [0, 0, 20]; So far I have it but I do not know how to do so that once you reach the desired height the rocket moves to the ship2, please help guys Share this post Link to post Share on other sites
Floof 57 Posted October 12, 2018 This should have all you need. 2 Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 hello friend, if I have seen that scripts and I have seen others, but that is called by laser destination, and others that I have seen is by clicking on the position of the map, but I need to appear as well as calling a scripts, currently the missile appears , and moves up, but I do not know how to adapt the objective later, how could it be added? Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 I'm reviewing this command but I do not know how to adapt it and see if it works https://community.bistudio.com/wiki/setVelocityTransformation Share this post Link to post Share on other sites
lordfrith 401 Posted October 12, 2018 13 minutes ago, elthefrank said: but that is called by laser destination i actually adapted that script so it was spawned with an offest to the source vehicle (i.e. a plane) and the target is just passed in params so no laser designator required. For my use it was to allow missiles to be used by AI side but it might have some ideas for you Spoiler LF_fnc_cruiseMissile = { /* this is by Kylania from his blog (http://www.kylania.com/ex/?p=21), i just edited the input parameters so the missle could be spawned in relation to a plane. */ params [ ["_spawnPos", [0,0,0]], ["_missileDelay", 3], // delay between hit and missile being available again ["_missileType", "M_Scalpel_AT"], //type of the missile ["_missileSpeed", 200], //speed of the missile ["_primaryTarget", objNull], //target for the missile ["_defaultTargetPos", [0,0,0]] //default position where unguided missiles will fly [8340.718750,3074.914795,0]; ]; if (isNull _primarytarget) exitWith { hint "No Target Found!"; //LFredAlert = false; publicVariable "LFredAlert"; }; if (!LF_missileAvailable) exitWith {hint "Missile already active!"}; LF_missileAvailable = false; publicVariable "LF_missileAvailable"; _missileStart = getPosWorld _spawnPos; _missleDir = getDir _spawnPos; _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 select 0, _missileStart select 1, (_missileStart select 2) - 5]; _missile setPosWorld [_missileStart select 0, _missileStart select 1, (_missileStart select 2) - 5]; _missile setDir _missleDir; //secondary target used for random trajectory when laser designator is turned off prematurily _secondaryTarget = "Land_HelipadEmpty_F" 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); _missile setDir (_missile getDir _target); _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; }; // This seems to get rid of the script errors for the 1-2 cycles after the missile is destroyed when _velocityX returns ANY if (isNil {_velocityX}) exitWith {velocity _missile}; [_velocityX, _velocityY, _velocityZ] }; _missile 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]]; hint "Missile on the way!"; //missile flying while {alive _missile} do { _velocityForCheck = _missile call _homeMissile; if (!(isNil {_velocityForCheck select 0}) && {_x isEqualType 0} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck}; if ({_x isEqualType 0} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck}; sleep (1 / _perSecondChecks); }; deleteVehicle _fireLight; deleteVehicle _secondaryTarget; sleep _missileDelay; hint "Missile available!"; LF_missileAvailable = true; publicVariable "LF_missileAvailable"; }; then it is spawned like so: Quote [_vehUAV,10,"ammo_Missile_Cruise_01",200,_quarry,getPos _quarry] spawn LF_fnc_cruiseMissile; EDIT: this works ok when fired from the air but if its being launched from ground then you might still need to insert your lines to make the missle fly upwards first 1 Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 I do not understand very well LordFrih, could you show me how to do it? Share this post Link to post Share on other sites
lordfrith 401 Posted October 12, 2018 well put the function above in your init.sqf so its loaded then try calling it with something like: Quote [ship1,10,"ammo_Missile_Cruise_01",200,boat2,getPos boat2] spawn LF_fnc_cruiseMissile; but as i added above you might need to make the missle fly upwards first before moving towards target as i was writing that to be launched from plane so missile already has altitude 1 Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 Thank you! @lordfrith I'm going to try it Share this post Link to post Share on other sites
lordfrith 401 Posted October 12, 2018 well i needed to do this too at some point so i've been messing about, see revised function below, i've highlighted in red the lines which set where the missile spawns and how long it flies up for this is in my init.sqf to test, i forgot to add the line 'LF_missileAvailable = true;' in init or the function will kick off with an unknown variable error Spoiler LF_fnc_cruiseMissile = { /* this is by Kylania from his blog (http://www.kylania.com/ex/?p=21), i just edited the input parameters so the missle could be spawned in relation to a plane. */ params [ ["_spawnPos", [0,0,0]], ["_missileDelay", 3], // delay between hit and missile being available again ["_missileType", "M_Scalpel_AT"], //type of the missile ["_missileSpeed", 200], //speed of the missile ["_primaryTarget", objNull], //target for the missile ["_defaultTargetPos", [0,0,0]] //default position where unguided missiles will fly [8340.718750,3074.914795,0]; ]; if (isNull _primarytarget) exitWith { hint "No Target Found!"; //LFredAlert = false; publicVariable "LFredAlert"; }; if (!LF_missileAvailable) exitWith {hint "Missile already active!"}; LF_missileAvailable = false; publicVariable "LF_missileAvailable"; _missileStart = getPosWorld _spawnPos; _missleDir = getDir _spawnPos; _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 select 0, _missileStart select 1, (_missileStart select 2) + 20];//sets vertical offset of missile spawn _missile setPosWorld [_missileStart select 0, _missileStart select 1, (_missileStart select 2) + 20];//sets vertical offset of missile spawn _missile setVectorDirAndUp [[0,0.5,0.5],[0,-0.5,0.5]];// missile flies up at 45 degree angle //_missile setVelocity [0, 0, 20];//ended up not needing this line Sleep 5;// time before missile starts homing behaviour _missile setDir _missleDir; //secondary target used for random trajectory when laser designator is turned off prematurily _secondaryTarget = "Land_HelipadEmpty_F" 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); _missile setDir (_missile getDir _target); _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; }; // This seems to get rid of the script errors for the 1-2 cycles after the missile is destroyed when _velocityX returns ANY if (isNil {_velocityX}) exitWith {velocity _missile}; [_velocityX, _velocityY, _velocityZ] }; _missile 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]]; hint "Missile on the way!"; //missile flying while {alive _missile} do { _velocityForCheck = _missile call _homeMissile; if (!(isNil {_velocityForCheck select 0}) && {_x isEqualType 0} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck}; if ({_x isEqualType 0} count _velocityForCheck == 3) then {_missile setVelocity _velocityForCheck}; sleep (1 / _perSecondChecks); }; deleteVehicle _fireLight; deleteVehicle _secondaryTarget; sleep _missileDelay; hint "Missile available!"; LF_missileAvailable = true; publicVariable "LF_missileAvailable"; //LFredAlert = false; publicVariable "LFredAlert"; }; LF_missileAvailable = true; seems to work pretty sweet now, heres my test scenario, enjoy! 1 Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 Exactly I was already writing to him that he was giving me a variable error Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 friend and what part of the scripst can I add to start flying up? Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 OHHH Magnifico, I just saw it is beautiful :o Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 Thank you very much @lordfrith I spent a lot of time trying to do this 1 Share this post Link to post Share on other sites
lordfrith 401 Posted October 12, 2018 Just now, elthefrank said: what part of the scripst can I add to start flying up? check my revised script in my last post i added it already ;) , its the line 5 minutes ago, lordfrith said: _missile setVectorDirAndUp [[0,0.5,0.5],[0,-0.5,0.5]];// missile flies up at 45 degree angle //_missile setVelocity [0, 0, 20];//ended up not needing this line Sleep 5;// time before missile starts homing behaviour 1 Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 @lordfrith a question once the missile goes in the air, if the target ship moves, the missile will follow it, or will the missile fall in the previous position of the target? Share this post Link to post Share on other sites
Barba-negra 117 Posted October 12, 2018 and another question bro, how do I change the speed of movement? Share this post Link to post Share on other sites
lordfrith 401 Posted October 13, 2018 1 hour ago, elthefrank said: if the target ship moves, the missile will follow it, or will the missile fall in the previous position of the target? yep, with unnerving accuracy, serious, you can't hide from this thing! try running it with yourself as a target then try fleeing! I'd use it for scenes or AI support calls, for players its more realistic to use the original laser pointer target one 55 minutes ago, elthefrank said: and another question bro, how do I change the speed of movement? 10 hours ago, lordfrith said: [ship1,10,"ammo_Missile_Cruise_01",200,boat2,getPos boat2] spawn LF_fnc_cruiseMissile; 1 Share this post Link to post Share on other sites
Barba-negra 117 Posted October 13, 2018 ok thanks @lordfrith Now I'm going to do something more complex, like I'm working on a boat, I'm trying to create a torpedo system with the same scripts, so far I've put the torpedo and it works very well, only now the torpedo is an object and not ammunition, then try to put a ammunition and touch the water it explodes, it is something more complex this second part of the work Share this post Link to post Share on other sites
Barba-negra 117 Posted October 13, 2018 I could solve it for now, I already managed to create the torpedoes, I'll be doing tests Share this post Link to post Share on other sites