jasonb 10 Posted July 10, 2016 Hi Guys, So I've been trying all day how to figure out how to launch a missile or another object from the players position. Before I give up I thought I'd ask here for help. I need the object to launch like a bullet would from a gun or from whichever direction and/or angle that the player is aiming/looking at called by a simple script or add action. Right now the object launches at which ever direction i'm facing at, but not up or down. If the player looks up and then calls the script, the object needs to launch upwards skywards for example. So wherever the player is aiming at the object needs to fly in that direction. Right now i've got: Bullet = "Land_canteen_f" createVehicle position player; Bullet setpos getpos Player; Bullet setPosATL (Bullet modelToWorld[0.23,1,1]); Bullet setDir getDir Player _vehicle = Bullet; _vel = velocity _vehicle; _speed = 100; _dir = direction _vehicle; _vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)]; Damage attachTo [bullet,[0, 0, 0]]; Any help would be greatly appreciated. Cheers. Share this post Link to post Share on other sites
kylania 568 Posted July 10, 2016 getCameraViewDirection might be helpful? 1 Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 10, 2016 Use a fired eventhandler, fetch the projectiles velocity vector and posATL, delete the projectile and spawn your "Land_canteen_f", setposATL it and give it the stored velocity vector of the projectile. Can limit it to thrown weapons too. Cheers Share this post Link to post Share on other sites
jasonb 10 Posted July 11, 2016 Use a fired eventhandler, fetch the projectiles velocity vector and posATL, delete the projectile and spawn your "Land_canteen_f", setposATL it and give it the stored velocity vector of the projectile. Can limit it to thrown weapons too. Cheers Hi Grumpy old man. Thanks for your help however I'm trying to do this by calling an add action rather than having to fire a gun if possible. Cheers. Share this post Link to post Share on other sites
jasonb 10 Posted July 11, 2016 getCameraViewDirection might be helpful? Sounds like the right track, would you know how to implement that to my little script? Thanks for the reply. Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 11, 2016 You can use the addaction to activate the eventhandler, after firing a shot or throwing a grenade you can remove the eventhandler. Throw.sqf: params ["_unit",["_itemToThrow","Land_canteen_f"]]; _unit setvariable ["ItemToThrow",_itemToThrow]; GOM_fnc_throwItem = { params ["_unit","_caller","_ID"]; _unit removeAction _ID; _item = _unit getvariable ["ItemToThrow","Land_canteen_f"]; hint format ["Ready to throw %1!\nHit your throw keybind!",_item]; _ID = _unit addEventHandler ["Fired",{ params ["_unit", "_weapon", "_muzzle","_mode","_ammo","_mag","_projectile"]; if (_weapon isEqualTo "Throw") then { _unit removeEventHandler ["Fired",_unit getVariable ["ThrowCanteenID",-1]]; _item = _unit getvariable ["ItemToThrow","Land_canteen_f"]; _throw = _item createVehicle [0,0,0]; _vel = velocity _projectile; _pos = getPosATLVisual _projectile; deletevehicle _projectile; _throw setPosATL _pos; _throw setVelocity _vel; _unit addMagazine _mag; }; true }]; _unit setVariable ["ThrowCanteenID",_ID]; }; _unit addAction ["Prepare to throw Item",{_this call GOM_fnc_throwItem},nil,6,true,true,"","_target isEqualTo _this AND _target isEqualTo vehicle _target"]; Pretty easy, just call it with: throw = [player] execVM "Throw.sqf"; If you want the action to stay on the unit simply remove the line "_unit removeAction _ID". There definitely should be a banana item in Arma. Cheers Share this post Link to post Share on other sites
jasonb 10 Posted July 12, 2016 Hi Grumpy Old man, Looks great. But just to confirm, there is no way around this other than turning it into a fired event handler? I'd like the player to be able to launch an attack (object with trigger attached) without a weapon in hand by calling an action so that I can develop custom attacks like Molotov's, shotguns etc without as far as going ahead as making a mod. I've got it working but projectile just launches from 1.35m and hits the ground at 20m or so but the idea is if I want to look up I should be launch the object 20m up and have it land down next to me. I'd also like the AI to use these attacks when an enemy gets too close (called by a trigger attached to the AI). AI will turn towards target and throw a molotov their way without firing a gun for example. Is this possible? Cheers. You can use the addaction to activate the eventhandler, after firing a shot or throwing a grenade you can remove the eventhandler. Throw.sqf: params ["_unit",["_itemToThrow","Land_canteen_f"]]; _unit setvariable ["ItemToThrow",_itemToThrow]; GOM_fnc_throwItem = { params ["_unit","_caller","_ID"]; _unit removeAction _ID; _item = _unit getvariable ["ItemToThrow","Land_canteen_f"]; hint format ["Ready to throw %1!\nHit your throw keybind!",_item]; _ID = _unit addEventHandler ["Fired",{ params ["_unit", "_weapon", "_muzzle","_mode","_ammo","_mag","_projectile"]; if (_weapon isEqualTo "Throw") then { _unit removeEventHandler ["Fired",_unit getVariable ["ThrowCanteenID",-1]]; _item = _unit getvariable ["ItemToThrow","Land_canteen_f"]; _throw = _item createVehicle [0,0,0]; _vel = velocity _projectile; _pos = getPosATLVisual _projectile; deletevehicle _projectile; _throw setPosATL _pos; _throw setVelocity _vel; _unit addMagazine _mag; }; true }]; _unit setVariable ["ThrowCanteenID",_ID]; }; _unit addAction ["Prepare to throw Item",{_this call GOM_fnc_throwItem},nil,6,true,true,"","_target isEqualTo _this AND _target isEqualTo vehicle _target"]; Pretty easy, just call it with: throw = [player] execVM "Throw.sqf"; If you want the action to stay on the unit simply remove the line "_unit removeAction _ID". There definitely should be a banana item in Arma. Cheers Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted July 12, 2016 What's wrong about a fired eventhandler? You can use it like throwing a grenade. Did you try my snippet? Use action -> throw your current "Throw" weapon (grenade, smoke, whatever) -> see how your item of choice is being thrown instead. No weapon in hand needed other than some grenade or smoke grenade in inventory. Works for AI aswell using switchweapon and doing some minor modifications to the snippet above. I'm using this very snippet to make AI use molotovs and other nasty stuff at the player group. Cheers Share this post Link to post Share on other sites
sarogahtyp 1108 Posted July 12, 2016 _initial_speed = 100; _velocity = eyeDirection player vectorMultiply _initial_speed; _molly = createVehicle ["molly_classname", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"]; _molly setVelocity _velocity; You could try this but its not tested. I would prefer grumpys solution because u would have a throw animation then but I think u could that implement in my solution with playMove as well. Share this post Link to post Share on other sites
jasonb 10 Posted July 12, 2016 Hi Grumpy Old man, Looks great. But just to confirm, there is no way around this other than turning it into a fired event handler? I'd like the player to be able to launch an attack (object with trigger attached) without a weapon in hand by calling an action so that I can develop custom attacks like Molotov's, shotguns etc without as far as going ahead as making a mod. I've got it working but projectile just launches from 1.35m and hits the ground at 20m or so but the idea is if I want to look up I should be launch the object 20m up and have it land down next to me. I'd also like the AI to use these attacks when an enemy gets too close (called by a trigger attached to the AI). AI will turn towards target and throw a molotov their way without firing a gun for example. Is this possible? Cheers. Hi Grumpy, could not get the script to work. Did I have to edit any of it? I get a msg Hint 'Ready to throw B Bravo (Jason) Hit your throw button.' I then press G and my character lobs a standard grenade and then the action disapears. I notice though that the variable 'throw' I think is one used by biz. Share this post Link to post Share on other sites
jasonb 10 Posted July 12, 2016 Ok cool, got it working when I changed 'Throw' to 'Throwz'. Was getting the error, reserved variable. Alright, I'm going to play around with this and let you know how I go. Question, if I want to be able to launch the grenade out to say 100-200m can I do that too? I notice you have no _speed modifier it appears that the canteen replaces the grenade and that it uses the grenades default velocity and speed etc. I'd like to be able to create addaction shotgun bursts and things like a plasma projectile (upcoming Predator mission). In that, the Predator launches a plasma attack out to 100m. Is it possible to do that with your script? Thanks for your help. What's wrong about a fired eventhandler? You can use it like throwing a grenade. Did you try my snippet? Use action -> throw your current "Throw" weapon (grenade, smoke, whatever) -> see how your item of choice is being thrown instead. No weapon in hand needed other than some grenade or smoke grenade in inventory. Works for AI aswell using switchweapon and doing some minor modifications to the snippet above. I'm using this very snippet to make AI use molotovs and other nasty stuff at the player group. Cheers Share this post Link to post Share on other sites
jasonb 10 Posted July 12, 2016 Ok cool, got it working when I changed 'Throw' to 'Throwz'. Was getting the error, error reserved variable in expression. Alright, I'm going to play around with this and let you know how I go. Question, if I want to be able to launch the grenade out to say 100-200m can I do that too? Just change Vel _initial_speed = 100; _velocity = eyeDirection player vectorMultiply _initial_speed; _molly = createVehicle ["molly_classname", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"]; _molly setVelocity _velocity; You could try this but its not tested. I would prefer grumpys solution because u would have a throw animation then but I think u could that implement in my solution with playMove as well. Hi Saro. How would I incorporate that into this? Or rewrite this with your suggestion? Thanks for the help. Bullet = "Land_canteen_f" createVehicle position player; Bullet setpos getpos Player; Bullet setPosATL (Bullet modelToWorld[0.23,1,1]); Bullet setDir getDir Player _vehicle = Bullet; _vel = velocity _vehicle; _speed = 100; _dir = direction _vehicle; _vehicle setVelocity [(_vel select 0)+(sin _dir*_speed),(_vel select 1)+ (cos _dir*_speed),(_vel select 2)]; Damage attachTo [bullet,[0, 0, 0]]; Share this post Link to post Share on other sites
jasonb 10 Posted July 12, 2016 _initial_speed = 100; _velocity = eyeDirection player vectorMultiply _initial_speed; _molly = createVehicle ["molly_classname", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"]; _molly setVelocity _velocity; You could try this but its not tested. I would prefer grumpys solution because u would have a throw animation then but I think u could that implement in my solution with playMove as well. Hi Saro, is this the complete script? As in, do I need to do anything else once I put in the Vehicle class name? So something like... _initial_speed = 100; _velocity = eyeDirection player vectorMultiply _initial_speed; _molly = createVehicle ["Land_canteen_f", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"]; _molly setVelocity _velocity; Player switchmove "Amovaksdnsddonorwhateveritis" Damage attachTo [_Molly,[0, 0, 0]]; Share this post Link to post Share on other sites
kylania 568 Posted July 12, 2016 Damage attachTo [_Molly,[0, 0, 0]]; Please never use a command name as a variable name. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted July 12, 2016 Hi Saro, is this the complete script? As in, do I need to do anything else once I put in the Vehicle class name? So something like... _initial_speed = 100;_velocity = eyeDirection player vectorMultiply _initial_speed;_molly = createVehicle ["Land_canteen_f", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"];_molly setVelocity _velocity; Player switchmove "Amovaksdnsddonorwhateveritis" Damage attachTo [_Molly,[0, 0, 0]]; I think u could just execute it with addAction command. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted July 12, 2016 this addAction ["Throw Molly", "_molly = createVehicle ['molly_classname', ASLToAGL eyePos (_this select 0), [], 0, 'CAN_COLLIDE']; _molly setVelocity ((eyeDirection (_this select 0)) vectorMultiply 100);" u could try to add that to players init line... but not tested. Share this post Link to post Share on other sites
jasonb 10 Posted July 13, 2016 Gonna try this now. How do you set the speed (distance) of spawned item? this addAction ["Throw Molly", "_molly = createVehicle ['molly_classname', ASLToAGL eyePos (_this select 0), [], 0, 'CAN_COLLIDE']; _molly setVelocity ((eyeDirection (_this select 0)) vectorMultiply 100);"u could try to add that to players init line... but not tested. Share this post Link to post Share on other sites
jasonb 10 Posted July 13, 2016 this addAction ["Throw Molly", "_molly = createVehicle ['molly_classname', ASLToAGL eyePos (_this select 0), [], 0, 'CAN_COLLIDE']; _molly setVelocity ((eyeDirection (_this select 0)) vectorMultiply 100);" u could try to add that to players init line... but not tested. Ok so just tried this: _velocity = eyeDirection player vectorMultiply _initial_speed; _molly = createVehicle ["Land_Canteen_F", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"]; _molly setVelocity ((eyeDirection (_this select 0)) vectorMultiply 100) And the item simply falls to the ground. With your first example, it seems like the item spawns in front of the players eyes and launches however looking up does not launch it upwards. So, still in a straight line. Anything else we can try? Thanks for your help. Share this post Link to post Share on other sites
jasonb 10 Posted July 13, 2016 Hey Guys. Here is the working script! Not sure if it works for AI though. Thanks for all your help. 0 = [100] spawn { params ["_speed"]; _bullet = "Land_canteen_f" createVehicle position player; _bullet setPosATL (player modelToWorld[0.23,1,1]); _vel = velocity player; _dir = direction player; _bullet setVelocity ((getCameraViewDirection player) vectorMultiply _speed) } Share this post Link to post Share on other sites
jasonb 10 Posted July 13, 2016 Hey Guys. Here is the working script! Not sure if it works for AI though. Thanks for all your help. 0 = [100] spawn { params ["_speed"]; _bullet = "Land_canteen_f" createVehicle position player; _bullet setPosATL (player modelToWorld[0.23,1,1]); _vel = velocity player; _dir = direction player; _bullet setVelocity ((getCameraViewDirection player) vectorMultiply _speed) } This works for players but not for AI. Does anyone know if there is a workaround for AI? I'm assuming it's because getCameraViewDirection is for players only. Cheers Share this post Link to post Share on other sites
Tajin 349 Posted July 13, 2016 For AI you need to use eyeDirection or weaponDirection instead. Personally however I would just use getDir and then determine the angle of throw depending on the distance to the target. Otherwise the AI wouldn't account for that anyways. Also... 4 posts in a row and you even fullquote your own posts? Seriously? Keep the forum clean: use the edit button and dont fullquote the last post! Share this post Link to post Share on other sites
sarogahtyp 1108 Posted July 13, 2016 (edited) Also... 4 posts in a row and you even fullquote your own posts? Seriously? Keep the forum clean: use the edit button and dont fullquote the last post! ... plus the same topic at armaholic forum ...http://www.armaholic.com/forums.php?m=posts&q=35377 Edit: ups wrong link above: http://www.armaholic.com/forums.php?m=posts&q=35363 Edited July 13, 2016 by sarogahtyp Share this post Link to post Share on other sites
sarogahtyp 1108 Posted July 13, 2016 Ok so just tried this: _velocity = eyeDirection player vectorMultiply _initial_speed; _molly = createVehicle ["Land_Canteen_F", ASLToAGL eyePos player, [], 0, "CAN_COLLIDE"]; _molly setVelocity ((eyeDirection (_this select 0)) vectorMultiply 100) And the item simply falls to the ground. With your first example, it seems like the item spawns in front of the players eyes and launches however looking up does not launch it upwards. So, still in a straight line. Anything else we can try? Thanks for your help. u did not set _initial_speed i think therefore it just falls down... Share this post Link to post Share on other sites