{"name":"fireAtTarget","title":"fireAtTarget","type":"command","url":"https://community.bistudio.com/wiki/fireAtTarget","revid":369417,"updated":"2024-09-03T18:48:49Z","groups":["Unit Control","Weapons"],"status":"ok","games":{"arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma2oa 1.50","arma3_since":"0.50","description":"Remotely forces a unit to fire the given weapon. See also BIS_fnc_fire.","syntaxes":[{"syntax":"sourceVehicle fireAtTarget [targetVehicle, weaponMuzzleName]","params":[{"name":"sourceVehicle","type":"Object","description":"source vehicle to fire from","type_expr":"Object"},{"name":"targetVehicle","type":"Object","description":"target vehicle to fire at","type_expr":"Object"},{"name":"weaponMuzzleName","type":"String","optional":true,"description":"weapon muzzle classname, optional parameter","type_expr":"String","text":"weaponMuzzleName: String - (Optional) weapon muzzle classname, optional parameter"}],"returns":{"type":"Boolean","type_expr":"Boolean","description":"true if fired, false if not"},"form":"binary","left":{"text":"sourceVehicle"},"right":{"text":"[targetVehicle, weaponMuzzleName]"}}],"examples":[{"code":["_handle = this fireAtTarget [groundtarget1, \"HellfireLauncher\"];"]},{"code":["_handle = Igla_AA_pod_TK_EP1 fireAtTarget [_helicopter, currentWeapon Igla_AA_pod_TK_EP1];"]},{"code":["_handle = Igla_AA_pod_TK_EP1 fireAtTarget [helicopter];"]}],"see_also":["fire","doFire","commandFire","canFire","forceWeaponFire","commandArtilleryFire","commandSuppressiveFire","doArtilleryFire","doSuppressiveFire","isManualFire","aimedAtTarget","BIS_fnc_fire"],"notes":[{"user":"Dwarden","date":"2010-09-16T08:17:00Z","text":"Most likely only for missiles and for interaction with player only."},{"user":"ffur2007slx2_5","date":"2014-04-08T16:50:00Z","text":"(Arma 3 1.14) Source vehicle is only limited to manned vehicle while any other types won’t be able to active fireAtTarget handle, e.g.\n\n```sqf\n_handle = _infantryUnit fireAtTarget [_infantryTarget, weapons _infantryUnit select 0];\n// false & no bullet shoot\n```\n\nTarget has no limitation and can be any object:\n\n```sqf\n_handle = (vehicle _veh) fireAtTarget [objNull, weapons (vehicle _veh) select 0];\n// true & a bullet shoot\n```\n\nHandle returns false if weapon class name is inaccurate, e.g.\n\n```sqf\n_handle = (vehicle _veh) fireAtTarget [ObjNull, \"UnknownWeapon\"];\n// false & no bullet shoot\n```\n\nHandle still returns true even though the vehicle is unavailable to shoot any bullet:\n\n```sqf\n_weapon = weapons (vehicle _veh) select 0;\n(vehicle _veh) setAmmo [_weapon, 0];\n_handle = (vehicle _veh) fireAtTarget [objNull, _weapon];\n// true & no bullet shoot\n```\n\n#### Difference\n\n| command | Source | Target | Behavior | Workaround templets |\n|---|---|---|---|---|\n| fire | Either unit or manned vehicle | N/A | Fired aiming at air for infantry rifle | Together with selectWeapon,<br>suggested to work with \"throw\",\"put\" weapon type<br>for infantry, or vehicle entity indeed. |\n| fireAtTarget | Manned vehicle only | Any object | Normal shoot, won’t aim at target automatically | ```sqf<br>_veh doWatch _target;<br>waitUntil { _veh aimedAtTarget [_target] > 0 };<br>_veh fireAtTarget [_target];<br>``` |\n| forceWeaponFire | Either unit or manned aircraft (weapon operator) | N/A | Normal shoot, can change fire mode | ```sqf<br>// e.g. unit won't shoot until he is facing the target<br>_unit doWatch _tar;<br>waitUntil {<br>    _dir = direction _unit;<br>    _relative = [_unit,_tar] call BIS_fnc_relativeDirTo;<br>    if (_dir == _relative) exitWith {<br>        _unit forceWeaponFire [currentWeapon _unit, \"single\"];<br>    };<br>    false<br>};<br>``` |\n| doFire | Unit only | Either unit or vehicle | automatic aiming and shooting | No special example. |\n| commandFire | Unit only | Either unit or vehicle | automatic aiming and shooting | No special example. |\n| action [\"UseWeapon\"] | Either unit or manned vehicle | N/A | unexpected behavior | N/A |"}]}