Arma 3 Scripting

weaponDirection

  • Global argument
  • Arma 3 v0.50
  • First in Operation Flashpoint: Elite v1.00

Command · also in Unit Control · Markdown · JSON · original wiki page

Description

Returns the direction that the vehicle weapon is aiming in. For addons the weapon name must be an entry in CfgWeapons.

Note

Turret and gun angle in degrees can also be obtained using animationSourcePhase or animationPhase commands.

Syntax

vehicleName weaponDirection weaponName

Parameters:

Returns: Vector3D

Examples

Example 1

_weaponVectorDir = player weaponDirection currentWeapon player;

Example 2

Draw AI eye direction (green) and weapon direction (red) in 3D:

bob = createGroup east createUnit ["O_Soldier_F", [0,0,0], [], 0, "NONE"];
bob setVehiclePosition [player modelToWorld [0,100,0], [], 0, "NONE"];
onEachFrame
{
    _beg = ASLToAGL eyePos bob;
    _endE = _beg vectorAdd (eyeDirection bob vectorMultiply 100);
    drawLine3D [_beg, _endE, [0,1,0,1]];
    _endW = _beg vectorAdd (bob weaponDirection currentWeapon bob vectorMultiply 100);
    drawLine3D [_beg, _endW, [1,0,0,1]];
};

See also

positionCameraToWorld · getCameraViewDirection · eyeDirection · vectorDir · vectorDirVisual

Community notes

HAC_mainframe

Works great in multiplayer. The numbers are representing offset as follows : [X axis,Y axis,Z axis]

The return array can be processed-converted into degrees as follows:

_array = _this weaponDirection "weapon class";
_dir_degrees = (_array select 0) atan2 (_array select 1);

Messiah2

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.

UNN

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.

Turret Animations (dead link) - new forum

Mechariuswh

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).