Stormmy1950 42 Posted April 8, 2022 Hi guys so i found this: and i wanted to recreate it. But i have a problem with setvelocity of a object. So if the cannon is stationary on a truck then its easy to have setvelocity of a Projectile but i want to be able to drive the vehicle and shoot the cannon to a direction that is pointing at. Right now the projectile is not effected by velocity it just spawn at position and falls. Also i would like to have a projectile to look like its beaing fired from a truck. Any help would be nice. This is my code so far: [] spawn { veh = "B_G_Van_01_transport_F" createVehicle position player; cannon = "Land_Fortress_01_cannon_F" createVehicle position player; smokeeffect = "Land_HelipadEmpty_F" createVehicle position player; cannon attachTo [veh, [0,-3,0],"",false]; cannon setVectorDirAndUp [[1,0,0],[0,0,1]]; smokeeffect attachTo[cannon,[3,0,1],"",false]; veh addEventHandler ["GetIn", { params ["_vehicle", "_role", "_unit", "_turret"]; player setVariable ["clickVic",_vehicle]; }]; waitUntil{!isNull findDisplay 46}; (findDisplay 46) displayAddEventHandler["MouseButtonDown",{ params["_display","_button"]; if(!isNull veh && {_button == 0 && driver veh == player && player getVariable ["clickVic",objNull] == vehicle player}) then { //hint "BOOM!!"; //_Ammo = "APERSMine_Range_Ammo" createVehicle position smokeeffect; //_Ammo setDamage 1; _Bullet = createVehicle ["Land_GasTank_01_khaki_F", position smokeeffect, [], 0, "CAN_COLLIDE"]; _Bullet setVelocity ((vectorDir cannon vectorAdd velocity cannon) vectorMultiply 20); _Bullet setVectorDir (vectorDir cannon); }; }]; }; Share this post Link to post Share on other sites
_foley 192 Posted April 8, 2022 Quote //_Ammo = "APERSMine_Range_Ammo" createVehicle position smokeeffect; //_Ammo setDamage 1; Detonating a mine to create some smoke - now that's authentic scripting 😄 Looks like a fun project. Here's a couple of issues in the script. 1. When you run setVectorDir, it resets velocity back to [0,0,0]. Move it up one line, before the setVelocity. 2. The bullet velocity calculation is largely dominated by the velocity of the vehicle so the orientation of the cannon has very little effect. You probably want to multiply only the part representing cannon direction. 3. (vectorDir cannon) is not necessarily pointing along the actual barrel Good luck! 2 Share this post Link to post Share on other sites
dreadedentity 278 Posted April 8, 2022 There is also setVelocityModelSpace that can (hopefully) eliminate any required trigonometry 1 Share this post Link to post Share on other sites
Stormmy1950 42 Posted April 8, 2022 12 minutes ago, dreadedentity said: There is also setVelocityModelSpace that can (hopefully) eliminate any required trigonometry Yea i know about that i was trying orginaly trying with that but it seams i need some math trigonometry to figure this one out. closes i got is this. But now cannon shoots always sideways and i dont know how to make it shoot from the front. [] spawn { veh = "B_G_Van_01_transport_F" createVehicle position player; cannon = "Land_Fortress_01_cannon_F" createVehicle position player; smokeeffect = "Land_HelipadEmpty_F" createVehicle position player; cannon attachTo [veh, [0,-3,0],"",false]; cannon setVectorDirAndUp [[1,0,0],[0,0,1]]; smokeeffect attachTo[cannon,[3,0,1],"",false]; veh addEventHandler ["GetIn", { params ["_vehicle", "_role", "_unit", "_turret"]; player setVariable ["clickVic",_vehicle]; }]; waitUntil{!isNull findDisplay 46}; (findDisplay 46) displayAddEventHandler["MouseButtonDown",{ params["_display","_button"]; if(!isNull veh && {_button == 0 && driver veh == player && player getVariable ["clickVic",objNull] == vehicle player}) then { //hint "BOOM!!"; //_Ammo = "APERSMine_Range_Ammo" createVehicle position smokeeffect; //_Ammo setDamage 1; _Bullet = createVehicle ["Land_GasTank_01_khaki_F", position smokeeffect, [], 0, "CAN_COLLIDE"]; _Bullet setVectorDir (vectorDir cannon); _Bullet setVelocity ((vectorDir cannon vectorMultiply 20) vectorAdd velocity cannon); }; }]; }; Share this post Link to post Share on other sites
Harzach 2518 Posted April 8, 2022 Those global variables make me nervous. Share this post Link to post Share on other sites
rowdied 44 Posted April 8, 2022 This most interesting part of that video is when the shell lands, then skids and hits the wall, bringing it to a stop and then explodes after a few seconds. Is there was a way to do this with bombs on planes? That would be awesome. 1 Share this post Link to post Share on other sites
Stormmy1950 42 Posted April 8, 2022 2 hours ago, Harzach said: Those global variables make me nervous. I know i need to touch up on the variables front i am still learning about that. if you have any example how could i make those variables local that would help so mutch. 1 hour ago, rowdied said: This most interesting part of that video is when the shell lands, then skids and hits the wall, bringing it to a stop and then explodes after a few seconds. Is there was a way to do this with bombs on planes? That would be awesome. I beleve that is done with timer or somekind a check where you wait for x amount of seconds or check istouchingground, create explostion where that object is and then delete object. Share this post Link to post Share on other sites
Harzach 2518 Posted April 8, 2022 10 minutes ago, Stormmy1950 said: how could i make those variables local A preceding underscore. myGlobalVariable; _myLocalVariable https://community.bistudio.com/wiki/Variables Share this post Link to post Share on other sites
Stormmy1950 42 Posted April 8, 2022 Just now, Harzach said: A preceding underscore. myGlobalVariable; _myLocalVariable https://community.bistudio.com/wiki/Variables I know that but then i cant use _veh and other variables inside the EventHandler witch is used for cheking if player honk a horn. Share this post Link to post Share on other sites
Harzach 2518 Posted April 8, 2022 18 minutes ago, Stormmy1950 said: I know that but then i cant use _veh and other variables inside the EventHandler witch is used for cheking if player honk a horn. A few solutions here: Share this post Link to post Share on other sites
SharpieMate 0 Posted June 3, 2022 Can this be used to set a speed limit for a player-controlled vehicle like a drone? The K-40 Ababil seems to be broken and can reach speeds of up 900+ kmph with its engine off. Share this post Link to post Share on other sites
sarogahtyp 1109 Posted June 3, 2022 1 hour ago, SharpieMate said: Can this be used to set a speed limit for a player-controlled vehicle like a drone? The K-40 Ababil seems to be broken and can reach speeds of up 900+ kmph with its engine off. 1 Share this post Link to post Share on other sites