attachTo: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Bot: Reverted to revision 97267 by demellion on 2016-09-01T17:54:18Z)
m (Some wiki formatting)
 
(106 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{RV|type=command
____________________________________________________________________________________________


| arma2 |= Game name
|game1= arma2
|version1= 1.00


|1.00|= Game version
|game2= arma2oa
|version2= 1.50


|arg= global |= Arguments in MP
|game3= tkoh
|version3= 1.00


|eff= global |= Effects in MP
|game4= arma3
____________________________________________________________________________________________
|version4= 0.50


|Attaches an object to another object. The offset is applied to the object center unless a memory point is provided. If no offset is specified, the offset used will be the current relative positioning of objects against each other. |= Description
|arg= global
____________________________________________________________________________________________


|object1 '''attachTo''' [object2, offset, memPoint] |= Syntax
|eff= global


|p1= object1: [[Object]] - object to attach|= Parameter 1
|gr1= Object Manipulation
|p2=  [object2, offset, memPoint]: [[Array]] |= Parameter 2
|p3=  object2: [[Object]] - object to attach to |= Parameter 3
|p4=  offset: (optional): [[Array]] - format [[PositionRelative]]  |= Parameter 4
|p5=  memPoint: (optional): [[String]] - see [[ArmA: Selection Translations]] for czech selections names |= Parameter 5


|descr= Attaches an object to another object.
* 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.
* If no offset is specified, the current offset between the two objects will be used.


|[[Nothing]] |= Return value
{{Feature|informative|
____________________________________________________________________________________________
* All direction commands, such as [[setDir]], [[setVectorDirAndUp]], etc. for an [[attachedObjects|attached object]] should be used '''relative''' to the reference object's direction (i.e. in model space), e.g <sqf inline>_attachedObj setDir 0</sqf> will make it face the same direction as the reference object, '''90''' face to the right, '''180''' face to the back, etc.
 
* Attached triggers only follow the direction of the object to which they are attached, not pitch or roll.
|x1= <code>[[player]] [[attachTo]] [car, [0, 0, 1] ]; </code> |= Example 1
}}
____________________________________________________________________________________________
 
|mp= Use <sqf inline>_attachedObj setPosWorld getPosWorld _attachedObj</sqf> ''after'' [[setDir]] to synchronise direction properly over the network (see {{Link|setDir|setDir's page}} for its MP behaviour).
 
|s1= object1 [[attachTo]] [object2, offset, memPoint, followBoneRotation]


|x2= <code>[[player]] [[attachTo]] [tank, [0, -1, 0], "Usti hlavne"]; </code> |= Example 2
|p1= object1: [[Object]] - object to attach
____________________________________________________________________________________________
 
|p2= object2: [[Object]] or [[Group]] - object to attach to; if a group is provided, its [[leader]] is used
 
|p3= offset: [[Array]] format [[Position#PositionRelative|PositionRelative]] - (Optional) the position relative to ''object2''<nowiki/>'s position
 
|p4= memPoint: [[String]] - (Optional) see {{Link|ArmA: Armed Assault: Selection Translations|Selection Translations}} for czech selections names
 
|p5= followBoneRotation: [[Boolean]] - (Optional) follows the memory point's rotation (if attached to one)
|p5since= arma3 2.02
 
|r1= [[Nothing]]
 
|x1= <sqf>player attachTo [car, [0, 0, 1]];</sqf>
 
|x2= <sqf>player attachTo [tank, [0, -1, 0], "Usti hlavne"];</sqf>


|x3= Automatic offset:
|x3= Automatic offset:
<code>ammoCrate [[attachTo]] <nowiki>[</nowiki>[[player]]];</code> |= Example 3
<sqf>ammoCrate attachTo [player];</sqf>
____________________________________________________________________________________________


|x4= <p style="margin-top: 0;">To set orientation of attached object use [[setVectorDirAndUp]] command:</p>
|x4= To set orientation of attached object use [[setVectorDirAndUp]] command:<br>
<code style="float: left; padding-right: 3em; margin-right: 1em; margin-top: 0;">_expl1 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
[[File:Sbomber.jpg|300x200px|right]]
_expl1 [[attachTo]] <nowiki>[</nowiki>[[player]], [-0.1, 0.1, 0.15], "Pelvis"];
<sqf>
_expl1 [[setVectorDirAndUp]] [ [0.5, 0.5, 0], [-0.5, 0.5, 0] ];
_expl1 = "DemoCharge_Remote_Ammo" createVehicle position player;
_expl2 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl1 attachTo [player, [-0.1, 0.1, 0.15], "Pelvis"];
_expl2 [[attachTo]] <nowiki>[</nowiki>[[player]], [0, 0.15, 0.15], "Pelvis"];
_expl1 setVectorDirAndUp [[0.5, 0.5, 0], [-0.5, 0.5, 0]];
_expl2 [[setVectorDirAndUp]] [ [1, 0, 0], [0, 1, 0] ];
_expl2 = "DemoCharge_Remote_Ammo" createVehicle position player;
_expl3 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl2 attachTo [player, [0, 0.15, 0.15], "Pelvis"];
_expl3 [[attachTo]] <nowiki>[</nowiki>[[player]], [0.1, 0.1, 0.15], "Pelvis"];
_expl2 setVectorDirAndUp [[1, 0, 0], [0, 1, 0]];
_expl3 [[setVectorDirAndUp]] [ [0.5, -0.5, 0], [0.5, 0.5, 0] ]; </code>
_expl3 = "DemoCharge_Remote_Ammo" createVehicle position player;
_expl3 attachTo [player, [0.1, 0.1, 0.15], "Pelvis"];
_expl3 setVectorDirAndUp [[0.5, -0.5, 0], [0.5, 0.5, 0]];
</sqf>


[[Image:Sbomber.jpg|300px]] |= Example 4
|x5= [[File:arma3_attachTo-example-worker-drill-and-radio.png|300x200px|right]]
____________________________________________________________________________________________
<sqf>
_drill attachTo [_worker, [0.0595885,-0.00950365,-0.13495], "RightForeArmRoll", true];
_drill setVectorDirAndUp [[0.536966,-0.00438141,-0.843605],[0.345872,0.913231,0.215406]];
_radio attachTo [_worker, [-0.100003,0.069064,0.153719], "Spine3", true];
_radio setVectorDirAndUp [[-0.144569,-0.48725,0.861354],[0.039712,0.866938,0.497072]];
</sqf>


|mp= Only has to be executed on one client. |= MPBEHAVIOUR
|seealso= [[attachedTo]] [[attachedObjects]] [[detach]] [[getRelPos]] [[attachObject]] [[attachedObject]] [[waypointAttachVehicle]] [[waypointAttachedVehicle]] [[lightAttachObject]] [[triggerAttachVehicle]] [[setVectorDir]] [[setVectorUp]] [[setVectorDirAndUp]] [[modelToWorld]] [[BIS_fnc_transformVectorDirAndUp]]
}}


| [[attachObject]], [[attachedObjects]], [[attachedTo]], [[waypointAttachVehicle]], [[waypointAttachedVehicle]], [[lightAttachObject]], [[triggerAttachVehicle]], [[attachedObject]], [[detach]], [[setVectorDir]], [[setVectorUp]], [[setVectorDirAndUp]], [[modelToWorld]] |= SEEALSO
{{Note
|user= TeaCup
|timestamp= 20110917192000
|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:
<sqf>SuitcaseObject attachTo [FoldingTableObject, [0,0,0]];</sqf>
You would expect the suitcase to jump to the pivot point of the table, and stick to it.<br>
Instead, 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.<br>
Dodgy objects when it comes to attaching things to them: most in Objects&nbsp;(small), Objects&nbsp;(signs), all of Objects&nbsp;(helpers) categories, etc.
}}


{{Note
|user= Pixinger
|timestamp= 20140328162200
|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.
<sqf>
private _target = myAmmoBox;
// create and attach charge
private _charge = "DemoCharge_Remote_Ammo_Scripted" createVehicle position player;
_charge attachTo [_target, [0, 0, 0.2]];
_charge setVectorDirAndUp [[0.5,0.5,0], [-0.5,0.5,0]];
// now detonate charge
detach _charge; // Important!
_charge setDamage 1;
</sqf>
}}
{{Note
|user= ffur2007slx2_5
|timestamp= 20140601230000
|text= [[attachTo]] overwrites [[setVectorDirAndUp]] if attached obj was changed to attach another one.
<sqf>
_obj attachTo [_logic,[0, 0, 0]];
_obj setVectorDirAndUp [[0, 1, 0], [0, 0, -1]];
_obj attachTo [_logic, [0, 0, 2]]; // vector no changes
_obj attachTo [_anotherOne, [0, 0, 0]]; // vector changes to default
</sqf>
|game= arma3
|version= 1.20
}}
{{Note
|user= ondrejkuzel
|timestamp= 20140925100000
|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.
}}
{{Note
|user= Demellion
|timestamp= 20160901175400
|text= Using [[attachTo]] with objects that have ragdoll physics (such as ammo boxes, containers, etc.) may cause unexpected behaviour.
When 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.
Vehicles 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.
}}
{{Note
|user= R3vo
|timestamp= 20190813125500
|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.
}}
}}


<h3 style="display:none">Notes</h3>
{{Note
<dl class="command_description">
|user= Leopard20
<!-- Note Section BEGIN -->
|timestamp= 20240510092248
<dd class="notedate">Posted on June 6, 2009 - 13:47
|text= To find all selection names of vehicle turrets for [[attachTo]], you can use this script:
<dt class="note">'''[[User:IceShade|IceShade]]'''<dd class="note">You can use [[setDir]] to change the direction of the attached object. The direction is relative to the object you attach it to, so '''setDir 180''' won't point to the south but to the rear of the object you attach it to.
<sqf>
Use [[setPos]] to synchronize the direction of the object in a network game.
params ["_veh"];
Example code:
private _turretSels = [];
<code>
_obj [[setDir]] 180;
_obj [[setPos]] [[getPos]] _obj;</code>


<dd class="notedate">Posted on September 17, 2011 - 19:20
isNil { // make sure the code runs unscheduled
<dt class="note">'''[[User:TeaCup|teaCup]]'''<dd class="note">
private _cfg = configOf _veh;
Some objects you cannot attach anything to. To be more precise, you can attach objects to them, but the behaviour is unexpected. For instance: <code>
_veh = createSimpleObject [getModelInfo _veh # 1, [0,0,0]]; // create a simple object instead of the actual vehicle
SuitcaseObject [[attachTo]] [FoldingTableObject, [0,0,0]];</code>
deleteVehicle _veh; // mark it for deletion in the next frame
You would expect the suitcase to jump to the pivot point of the table, and stick to it.
Instead, the suitcase will freeze in it's 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's even weirder, the suitcase would turn invisible.
Dodgy objects when it comes to attaching things to them: most in Objects(small), Objects(signs), all of Objects(helpers) categories, etc..


<dd class="notedate">Posted on March 28, 2014 - 16:22
private _turrets = configProperties [_cfg >> "Turrets", "isClass _x", true];
<dt class="note">'''[[User:Pixinger77|Pixinger77]]'''<dd class="note">
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.
<code>[[private]] ["_target"];
_target = <<your_ammobox>>;
// create and attach charge
[[private]] ["_charge"];
_charge = "DemoCharge_Remote_Ammo_Scripted" [[createVehicle]] [[position]] [[player]];
_charge [[attachTo]] [_target, [0,0,0.2]];
_charge [[setVectorDirAndUp]] [[0.5,0.5,0],[-0.5,0.5,0]];
// now detonate charge
[[detach]] _charge; //Important!
_charge [[setDamage]] 1;
</code>


<dd class="notedate">Posted on 1 Jun, 2014 - 2300
private _getSelections = {_veh selectionNames "memory" apply {[_x, _veh selectionPosition [_x, "memory"], _veh selectionVectorDirAndUp [_x, "memory"]]}};
<dt class="note">'''[[User:ffur2007slx2_5|ffur2007slx2_5]]'''<dd class="note">
private _allSelections = call _getSelections;
(ArmA3 ver 1.20) [[attachTo]] overwrites [[setVectorDirAndUp]] if attached obj was changed to attach another one.
<code>
_obj [[attachTo]] [_logic,[0,0,0]];
_obj [[setVectorDirAndUp]] [[0,1,0],[0,0,-1]];
_obj [[attachTo]] [_logic,[0,0,2]]; //vector no changes
_obj [[attachTo]] [_anotherOne,[0,0,0]]; //vector changes to default
</code>


<dd class="notedate">Posted on September 25, 2014 - 10:00
{
<dt class="note">'''[[User:ondrejkuzel|ondrejkuzel]]'''<dd class="note">
private _gun = getText (_x >> "gun");
Attaching an object does not update the accessibility of a place for the AI. The command shouldn't be used for positioning large static objects - the AI will simply walk thru such objects.
_veh animate [_gun, 0.4, true];
private _newSels = call _getSelections;
_turretSels append (_newSels - _allSelections);
_veh animate [_gun, 0, true];
} forEach _turrets;
};


<!-- Note Section END -->
_turretSels = _turretSels apply { _x # 0 };
</dl>
_turretSels arrayIntersect _turretSels
</sqf>


<h3 style="display:none">Bottom Section</h3>
Just pass your vehicle to this code, for example, like this:
[[Category:ArmA 2: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
<sqf>
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[myVehicle] call MY_fnc_getTurretSelections; // MY_fnc_getTurretSelections is the above function
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
</sqf>
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]


<!-- CONTINUE Notes -->
If you simply need the end point of the gun(s), use this code instead:
<dl class="command_description">
<sqf>
<dd class="notedate">Posted on September 1, 2016 - 17:54 (UTC)</dd>
params ["_veh"];
<dt class="note">[[User:Demellion|Demellion]]</dt>
configProperties [configOf _veh >> "Turrets", "isClass _x", true] apply { getText (_x >> "gunBeg") };
<dd class="note">
</sqf>
Using '''attachTo''' with an objects that have ragdoll physics (such as ammo boxes, containers, etc.) may cause unexpected behaviour. When 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. Vehicles may start flipping with no mass calculation (ie tank might fly), player object might gain inifinite
Z-vector velocity on any interaction with terrain relief and other objects.
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 14:44, 15 May 2024

Hover & click on the images for description

Description

Description:
Attaches an object to another object.
  • 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.
  • If no offset is specified, the current offset between the two objects will be used.
  • 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.
  • Attached triggers only follow the direction of the object to which they are attached, not pitch or roll.
Multiplayer:
Use _attachedObj setPosWorld getPosWorld _attachedObj after setDir to synchronise direction properly over the network (see setDir's page for its MP behaviour).
Groups:
Object Manipulation

Syntax

Syntax:
object1 attachTo [object2, offset, memPoint, followBoneRotation]
Parameters:
object1: Object - object to attach
object2: Object or Group - object to attach to; if a group is provided, its leader is used
offset: Array format PositionRelative - (Optional) the position relative to object2's position
memPoint: String - (Optional) see Selection Translations for czech selections names
since Arma 3 logo black.png2.02
followBoneRotation: Boolean - (Optional) follows the memory point's rotation (if attached to one)
Return Value:
Nothing

Examples

Example 1:
player attachTo [car, [0, 0, 1]];
Example 2:
player attachTo [tank, [0, -1, 0], "Usti hlavne"];
Example 3:
Automatic offset:
ammoCrate attachTo [player];
Example 4:
To set orientation of attached object use setVectorDirAndUp command:
Sbomber.jpg
_expl1 = "DemoCharge_Remote_Ammo" createVehicle position player; _expl1 attachTo [player, [-0.1, 0.1, 0.15], "Pelvis"]; _expl1 setVectorDirAndUp [[0.5, 0.5, 0], [-0.5, 0.5, 0]]; _expl2 = "DemoCharge_Remote_Ammo" createVehicle position player; _expl2 attachTo [player, [0, 0.15, 0.15], "Pelvis"]; _expl2 setVectorDirAndUp [[1, 0, 0], [0, 1, 0]]; _expl3 = "DemoCharge_Remote_Ammo" createVehicle position player; _expl3 attachTo [player, [0.1, 0.1, 0.15], "Pelvis"]; _expl3 setVectorDirAndUp [[0.5, -0.5, 0], [0.5, 0.5, 0]];
Example 5:
arma3 attachTo-example-worker-drill-and-radio.png
_drill attachTo [_worker, [0.0595885,-0.00950365,-0.13495], "RightForeArmRoll", true]; _drill setVectorDirAndUp [[0.536966,-0.00438141,-0.843605],[0.345872,0.913231,0.215406]]; _radio attachTo [_worker, [-0.100003,0.069064,0.153719], "Spine3", true]; _radio setVectorDirAndUp [[-0.144569,-0.48725,0.861354],[0.039712,0.866938,0.497072]];

Additional Information

See also:
attachedTo attachedObjects detach getRelPos attachObject attachedObject waypointAttachVehicle waypointAttachedVehicle lightAttachObject triggerAttachVehicle setVectorDir setVectorUp setVectorDirAndUp modelToWorld BIS_fnc_transformVectorDirAndUp

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
TeaCup - c
Posted on Sep 17, 2011 - 19:20 (UTC)
Some objects you cannot attach anything to. To be more precise, you can attach objects to them, but the behaviour is unexpected. For instance:
SuitcaseObject attachTo [FoldingTableObject, [0,0,0]];
You would expect the suitcase to jump to the pivot point of the table, and stick to it.
Instead, 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.
Dodgy objects when it comes to attaching things to them: most in Objects (small), Objects (signs), all of Objects (helpers) categories, etc.
Pixinger - c
Posted on Mar 28, 2014 - 16:22 (UTC)
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.
private _target = myAmmoBox; // create and attach charge private _charge = "DemoCharge_Remote_Ammo_Scripted" createVehicle position player; _charge attachTo [_target, [0, 0, 0.2]]; _charge setVectorDirAndUp [[0.5,0.5,0], [-0.5,0.5,0]]; // now detonate charge detach _charge; // Important! _charge setDamage 1;
ffur2007slx2_5 - c
Posted on Jun 01, 2014 - 23:00 (UTC)

attachTo overwrites setVectorDirAndUp if attached obj was changed to attach another one.

_obj attachTo [_logic,[0, 0, 0]]; _obj setVectorDirAndUp [[0, 1, 0], [0, 0, -1]]; _obj attachTo [_logic, [0, 0, 2]]; // vector no changes _obj attachTo [_anotherOne, [0, 0, 0]]; // vector changes to default

ondrejkuzel - c
Posted on Sep 25, 2014 - 10:00 (UTC)
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.
Demellion - c
Posted on Sep 01, 2016 - 17:54 (UTC)
Using attachTo with objects that have ragdoll physics (such as ammo boxes, containers, etc.) may cause unexpected behaviour. When 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. Vehicles 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.
R3vo - c
Posted on Aug 13, 2019 - 12:55 (UTC)
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.
Leopard20 - c
Posted on May 10, 2024 - 09:22 (UTC)
To find all selection names of vehicle turrets for attachTo, you can use this script:
params ["_veh"]; private _turretSels = []; isNil { // make sure the code runs unscheduled private _cfg = configOf _veh; _veh = createSimpleObject [getModelInfo _veh # 1, [0,0,0]]; // create a simple object instead of the actual vehicle deleteVehicle _veh; // mark it for deletion in the next frame private _turrets = configProperties [_cfg >> "Turrets", "isClass _x", true]; private _getSelections = {_veh selectionNames "memory" apply {[_x, _veh selectionPosition [_x, "memory"], _veh selectionVectorDirAndUp [_x, "memory"]]}}; private _allSelections = call _getSelections; { private _gun = getText (_x >> "gun"); _veh animate [_gun, 0.4, true]; private _newSels = call _getSelections; _turretSels append (_newSels - _allSelections); _veh animate [_gun, 0, true]; } forEach _turrets; }; _turretSels = _turretSels apply { _x # 0 }; _turretSels arrayIntersect _turretSels
Just pass your vehicle to this code, for example, like this:
[myVehicle] call MY_fnc_getTurretSelections; // MY_fnc_getTurretSelections is the above function
If you simply need the end point of the gun(s), use this code instead:
params ["_veh"]; configProperties [configOf _veh >> "Turrets", "isClass _x", true] apply { getText (_x >> "gunBeg") };