{"name":"weaponDirection","title":"weaponDirection","type":"command","url":"https://community.bistudio.com/wiki/weaponDirection","revid":379484,"updated":"2026-10-31T00:12:40Z","groups":["Weapons","Unit Control"],"status":"ok","games":{"ofpe":"1.00","arma1":"1.00","arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"ofpe 1.00","arma3_since":"0.50","locality":{"argument":"global"},"description":"Returns the direction that the vehicle weapon is aiming in. For addons the weapon name must be an entry in CfgWeapons.\n\n> [!NOTE]\n> Turret and gun angle in degrees can also be obtained using animationSourcePhase or animationPhase commands.","syntaxes":[{"syntax":"vehicleName weaponDirection weaponName","params":[{"name":"vehicleName","type":"Object","type_expr":"Object"},{"name":"weaponName","type":"String","type_expr":"String"}],"returns":{"type":"Vector3D","type_expr":"Vector3D"},"form":"binary","left":{"text":"vehicleName"},"right":{"text":"weaponName"}}],"examples":[{"code":["_weaponVectorDir = player weaponDirection currentWeapon player;"]},{"text":"Draw AI eye direction (green) and weapon direction (red) in 3D:\n\n```sqf\nbob = createGroup east createUnit [\"O_Soldier_F\", [0,0,0], [], 0, \"NONE\"];\nbob setVehiclePosition [player modelToWorld [0,100,0], [], 0, \"NONE\"];\nonEachFrame\n{\n    _beg = ASLToAGL eyePos bob;\n    _endE = _beg vectorAdd (eyeDirection bob vectorMultiply 100);\n    drawLine3D [_beg, _endE, [0,1,0,1]];\n    _endW = _beg vectorAdd (bob weaponDirection currentWeapon bob vectorMultiply 100);\n    drawLine3D [_beg, _endW, [1,0,0,1]];\n};\n```","code":["bob = createGroup east createUnit [\"O_Soldier_F\", [0,0,0], [], 0, \"NONE\"];\nbob setVehiclePosition [player modelToWorld [0,100,0], [], 0, \"NONE\"];\nonEachFrame\n{\n\t_beg = ASLToAGL eyePos bob;\n\t_endE = _beg vectorAdd (eyeDirection bob vectorMultiply 100);\n\tdrawLine3D [_beg, _endE, [0,1,0,1]];\n\t_endW = _beg vectorAdd (bob weaponDirection currentWeapon bob vectorMultiply 100);\n\tdrawLine3D [_beg, _endW, [1,0,0,1]];\n};"]}],"see_also":["positionCameraToWorld","getCameraViewDirection","eyeDirection","vectorDir","vectorDirVisual"],"notes":[{"user":"HAC_mainframe","date":"2007-08-18T12:18:00Z","text":"Works great in multiplayer.\nThe numbers are representing offset as follows : [X axis,Y axis,Z axis]\n\nThe return array can be processed-converted into degrees as follows:\n\n```sqf\n_array = _this weaponDirection \"weapon class\";\n_dir_degrees = (_array select 0) atan2 (_array select 1);\n```"},{"user":"Messiah2","date":"2007-11-11T01:41:00Z","text":"WeaponClass can only be the primary turret of the vehicle. For example it is not possible to get direction of commander's M2 on M1Abrams."},{"user":"UNN","date":"2007-11-13T15:54:00Z","text":"For an alternative to the weaponDirection command, see the following post on the official forums. On how to obtain the direction of multiple turrets on vehicles.\n\n*Turret Animations* (dead link) - [new forum](http://forums.bistudio.com/showthread.php?t=63918)"},{"user":"Mechariuswh","date":"2014-12-09T18:25:00Z","text":"The suggestion above using atan2 and weaponDirection get the direction the barrel of a weapon is pointing, but this is not the same as the direction a shell will be fired (verify this by getting in an M4 Scorcher, parking it on a slope, elevating the barrel \"across\" the slope and watching the shell come out in third person)."}]}