{"name":"attachTo","operator":null,"title":"attachTo","type":"command","url":"https://community.bistudio.com/wiki/attachTo","revid":378853,"updated":"2026-07-20T13:40:14Z","groups":["Object Manipulation"],"status":"ok","replaced_by":[],"games":[{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma2","name":"Arma 2","version":"1.00"},"arma3_since":"0.50","branch":null,"locality":{"argument":"global","effect":"global","server_exec":false},"exec":null,"description":"Attaches an object to another object.\n- The offset is applied to the object center unless a memory point is provided, in which case the offset will be applied to the memory point position.\n- If no offset is specified, the current offset between the two objects will be used.\n\n> [!NOTE]\n> - All direction commands, such as setDir, setVectorDirAndUp, etc. for an attached object should be used **relative** to the reference object's direction (i.e. in model space), e.g `_attachedObj setDir 0` will make it face the same direction as the reference object, **90** face to the right, **180** face to the back, etc.\n> - Attached triggers only follow the direction of the object to which they are attached, not pitch or roll.","syntaxes":[{"syntax":"object1 attachTo [object2, offset, memPoint, followBoneRotation]","since":null,"effect":null,"exec":null,"params":[{"name":"object1","type":"Object","optional":false,"default":null,"description":"object to attach","types":["Object"],"since":null,"text":"object1: Object - object to attach"},{"name":"object2","type":"Object or Group","optional":false,"default":null,"description":"object to attach to; if a group is provided, its leader is used","types":["Object","Group"],"since":null,"text":"object2: Object or Group - object to attach to; if a group is provided, its leader is used"},{"name":"offset","type":"PositionRelative","optional":true,"default":null,"description":"the position relative to *object2*'s position","types":["PositionRelative"],"since":null,"text":"offset: PositionRelative - (Optional) the position relative to *object2*'s position"},{"name":"memPoint","type":"String","optional":true,"default":null,"description":"see Selection Translations for czech selections names","types":["String"],"since":null,"text":"memPoint: String - (Optional) see Selection Translations for czech selections names"},{"name":"followBoneRotation","type":"Boolean","optional":true,"default":null,"description":"follows the memory point's rotation (if attached to one)","types":["Boolean"],"since":"arma3 2.02","text":"followBoneRotation: Boolean - (Optional) follows the memory point's rotation (if attached to one)"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"object1","types":["Object"]},"right":{"text":"[object2, offset, memPoint, followBoneRotation]","types":["Array"]}}],"examples":[{"text":"```sqf\nplayer attachTo [car, [0, 0, 1]];\n```","code":["player attachTo [car, [0, 0, 1]];"]},{"text":"```sqf\nplayer attachTo [tank, [0, -1, 0], \"Usti hlavne\"];\n```","code":["player attachTo [tank, [0, -1, 0], \"Usti hlavne\"];"]},{"text":"Automatic offset:\n\n```sqf\nammoCrate attachTo [player];\n```","code":["ammoCrate attachTo [player];"]},{"text":"To set orientation of attached object use setVectorDirAndUp command:\n\n```sqf\n_expl1 = \"DemoCharge_Remote_Ammo\" createVehicle position player;\n_expl1 attachTo [player, [-0.1, 0.1, 0.15], \"Pelvis\"];\n_expl1 setVectorDirAndUp [[0.5, 0.5, 0], [-0.5, 0.5, 0]];\n_expl2 = \"DemoCharge_Remote_Ammo\" createVehicle position player;\n_expl2 attachTo [player, [0, 0.15, 0.15], \"Pelvis\"];\n_expl2 setVectorDirAndUp [[1, 0, 0], [0, 1, 0]];\n_expl3 = \"DemoCharge_Remote_Ammo\" createVehicle position player;\n_expl3 attachTo [player, [0.1, 0.1, 0.15], \"Pelvis\"];\n_expl3 setVectorDirAndUp [[0.5, -0.5, 0], [0.5, 0.5, 0]];\n```","code":["_expl1 = \"DemoCharge_Remote_Ammo\" createVehicle position player;\n_expl1 attachTo [player, [-0.1, 0.1, 0.15], \"Pelvis\"];\n_expl1 setVectorDirAndUp [[0.5, 0.5, 0], [-0.5, 0.5, 0]];\n_expl2 = \"DemoCharge_Remote_Ammo\" createVehicle position player;\n_expl2 attachTo [player, [0, 0.15, 0.15], \"Pelvis\"];\n_expl2 setVectorDirAndUp [[1, 0, 0], [0, 1, 0]];\n_expl3 = \"DemoCharge_Remote_Ammo\" createVehicle position player;\n_expl3 attachTo [player, [0.1, 0.1, 0.15], \"Pelvis\"];\n_expl3 setVectorDirAndUp [[0.5, -0.5, 0], [0.5, 0.5, 0]];"]},{"text":"```sqf\n_drill attachTo [_worker, [0.0595885,-0.00950365,-0.13495], \"RightForeArmRoll\", true];\n_drill setVectorDirAndUp [[0.536966,-0.00438141,-0.843605],[0.345872,0.913231,0.215406]];\n_radio attachTo [_worker, [-0.100003,0.069064,0.153719], \"Spine3\", true];\n_radio setVectorDirAndUp [[-0.144569,-0.48725,0.861354],[0.039712,0.866938,0.497072]];\n```","code":["_drill attachTo [_worker, [0.0595885,-0.00950365,-0.13495], \"RightForeArmRoll\", true];\n_drill setVectorDirAndUp [[0.536966,-0.00438141,-0.843605],[0.345872,0.913231,0.215406]];\n_radio attachTo [_worker, [-0.100003,0.069064,0.153719], \"Spine3\", true];\n_radio setVectorDirAndUp [[-0.144569,-0.48725,0.861354],[0.039712,0.866938,0.497072]];"]}],"multiplayer":"Use `_attachedObj setPosWorld getPosWorld _attachedObj` *after* setDir to synchronise direction properly over the network (see setDir's page for its MP behaviour).","problems":null,"aliases":[],"see_also":["attachedTo","attachedObjects","detach","getRelPos","attachObject","attachedObject","waypointAttachVehicle","waypointAttachedVehicle","lightAttachObject","triggerAttachVehicle","setVectorDir","setVectorUp","setVectorDirAndUp","modelToWorld","BIS_fnc_transformVectorDirAndUp","BIS_fnc_attachToRelative"],"notes":[{"user":"TeaCup","date":"2011-09-17T19:20:00Z","text":"Some objects you cannot attach anything to. To be more precise, you can attach objects to them, but the behaviour is unexpected. For instance:\n\n```sqf\nSuitcaseObject attachTo [FoldingTableObject, [0,0,0]];\n```\n\nYou would expect the suitcase to jump to the pivot point of the table, and stick to it.\n\nInstead, the suitcase will freeze in it is original position. Even if the table is moved, the suitcase will be unaffected: it will not follow the table, it will not even respond to actions it reacted to prior to being attached: pushing, being shot at, etc.. It's just an object frozen in space. In MP it is even weirder, the suitcase would turn invisible.\n\nDodgy objects when it comes to attaching things to them: most in Objects (small), Objects (signs), all of Objects (helpers) categories, etc."},{"user":"Pixinger","date":"2014-03-28T16:22:00Z","text":"If you attach an explosive charge to an object (e.g. ammobox), the charge will not detonate when you simply set the damage to 1. You must detach it before.\n\n```sqf\nprivate _target = myAmmoBox;\n// create and attach charge\nprivate _charge = \"DemoCharge_Remote_Ammo_Scripted\" createVehicle position player;\n_charge attachTo [_target, [0, 0, 0.2]];\n_charge setVectorDirAndUp [[0.5,0.5,0], [-0.5,0.5,0]];\n// now detonate charge\ndetach _charge; // Important!\n_charge setDamage 1;\n```"},{"user":"ffur2007slx2_5","date":"2014-06-01T23:00:00Z","text":"attachTo overwrites setVectorDirAndUp if attached obj was changed to attach another one.\n\n```sqf\n_obj attachTo [_logic,[0, 0, 0]];\n_obj setVectorDirAndUp [[0, 1, 0], [0, 0, -1]];\n_obj attachTo [_logic, [0, 0, 2]];        // vector no changes\n_obj attachTo [_anotherOne, [0, 0, 0]];    // vector changes to default\n```"},{"user":"ondrejkuzel","date":"2014-09-25T10:00:00Z","text":"Attaching an object does not update the accessibility of a place for the AI. The command **should not** be used for positioning large static objects - the AI will simply walk through such objects."},{"user":"Demellion","date":"2016-09-01T17:54:00Z","text":"Using attachTo with objects that have ragdoll physics (such as ammo boxes, containers, etc.) may cause unexpected behaviour.\nWhen you do so, if the attached object intersect origin object, origin object may gain some **enormous collision properties** even if the collision model for the attached object is not present localy to origin object, until detached.\nVehicles may start flipping with no mass calculation (ie tank might fly), player object might gain infinite Z-vector velocity on any interaction with terrain relief and other objects."},{"user":"R3vo","date":"2019-08-13T12:55:00Z","text":"When attaching a unit which is playing an animation to a static object, the animation becomes laggy. Presumably because the update frequency of the static object is used."},{"user":"Leopard20","date":"2024-05-10T09:22:48Z","text":"To find all selection names of vehicle turrets for attachTo, you can use this script:\n\n```sqf\nparams [\"_veh\"];\nprivate _turretSels = [];\n\nisNil { // make sure the code runs unscheduled\n    private _cfg = configOf _veh;\n    _veh = createSimpleObject [getModelInfo _veh # 1, [0,0,0]]; // create a simple object instead of the actual vehicle\n    deleteVehicle _veh; // mark it for deletion in the next frame\n\n    private _turrets = configProperties [_cfg >> \"Turrets\", \"isClass _x\", true];\n\n    private _getSelections = {_veh selectionNames \"memory\" apply {[_x, _veh selectionPosition [_x, \"memory\"], _veh selectionVectorDirAndUp [_x, \"memory\"]]}};\n    private _allSelections = call _getSelections;\n\n    {\n        private _gun = getText (_x >> \"gun\");\n        _veh animate [_gun, 0.4, true];\n        private _newSels = call _getSelections;\n        _turretSels append (_newSels - _allSelections);\n        _veh animate [_gun, 0, true];\n    } forEach _turrets;\n};\n\n_turretSels = _turretSels apply { _x # 0 };\n_turretSels arrayIntersect _turretSels\n```\n\nJust pass your vehicle to this code, for example, like this:\n\n```sqf\n[myVehicle] call MY_fnc_getTurretSelections; // MY_fnc_getTurretSelections is the above function\n```\n\nIf you simply need the end point of the gun(s), use this code instead:\n\n```sqf\nparams [\"_veh\"];\nconfigProperties [configOf _veh >> \"Turrets\", \"isClass _x\", true] apply { getText (_x >> \"gunBeg\") };\n```"}],"categories":["Arma 2: New Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Object Manipulation","Introduced with Arma 2 version 1.00","Scripting Commands","Scripting Commands: Global Effect","Take On Helicopters: Scripting Commands"]}