attachTo: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(syntax)
m (Add trigger info)
(17 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{Command|= Comments
{{Command|Comments=
____________________________________________________________________________________________
____________________________________________________________________________________________


| arma2 |= Game name
| arma2 |Game name=


|1.00|= Game version
|1.00|Game version=


|arg= global |= Arguments in MP
|arg= global |Multiplayer Arguments=


|eff= global |= Effects in MP
|eff= global |Multiplayer Effects=
____________________________________________________________________________________________
____________________________________________________________________________________________


|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
| 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.
 
{{Informative | Using [[setDir]] on an [[attachedObjects|attached object]] sets its direction '''relative''' to the reference object's direction, e.g '''0''' will make it face the same direction as the reference object, '''90''' face to the right, '''180''' face to the back, etc.<br>
Attached triggers only follow the direction of the object to which they are attached, not pitch or roll.}} |DESCRIPTION=
|mp= use {{Inline code|_attachedObj [[setPos]] [[getPos]] _attachedObj}} after [[setDir]] to synchronise set direction over the network (see [[setDir|setDir's page]] for its MP behaviour). |MULTIPLAYER=
____________________________________________________________________________________________
____________________________________________________________________________________________


|object1 '''attachTo''' [object2, offset, memPoint] |= Syntax
|object1 [[attachTo]] [object2, offset, memPoint] |SYNTAX=
 
|p1= object1: [[Object]] - object to attach|PARAMETER1=
 
|p2= object2: [[Object]] - object to attach to |PARAMETER2=


|p1=  object1: [[Object]] - object to attach|= Parameter 1
|p3= offset: [[Array]] - (Optional) format [[PositionRelative]] |PARAMETER3=
|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


|p4= memPoint: [[String]] - (Optional) see [[ArmA: Selection Translations]] for czech selections names |PARAMETER4=


|[[Nothing]] |= Return value
| [[Nothing]] |RETURNVALUE=
____________________________________________________________________________________________
____________________________________________________________________________________________
   
   
|x1= <code>[[player]] [[attachTo]] [car, [0, 0, 1] ]; </code> |= Example 1
|x1= <code>[[player]] [[attachTo]] [car, [0, 0, 1]]; </code> |EXAMPLE1=
____________________________________________________________________________________________


|x2= <code>[[player]] [[attachTo]] [tank, [0, -1, 0], "Usti hlavne"]; </code> |= Example 2
|x2= <code>[[player]] [[attachTo]] [tank, [0, -1, 0], "Usti hlavne"];</code> |EXAMPLE2=
____________________________________________________________________________________________


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


|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|300px|right]]
_expl1 [[attachTo]] <nowiki>[</nowiki>[[player]], [-0.1, 0.1, 0.15], "Pelvis"];
_expl1 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl1 [[setVectorDirAndUp]] [ [0.5, 0.5, 0], [-0.5, 0.5, 0] ];
_expl1 [[attachTo]] [<nowiki/>[[player]], [-0.1, 0.1, 0.15], "Pelvis"];
_expl2 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl1 [[setVectorDirAndUp]] [<nowiki/>[0.5, 0.5, 0], [-0.5, 0.5, 0]];
_expl2 [[attachTo]] <nowiki>[</nowiki>[[player]], [0, 0.15, 0.15], "Pelvis"];
_expl2 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl2 [[setVectorDirAndUp]] [ [1, 0, 0], [0, 1, 0] ];
_expl2 [[attachTo]] [<nowiki/>[[player]], [0, 0.15, 0.15], "Pelvis"];
_expl3 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl2 [[setVectorDirAndUp]] [<nowiki/>[1, 0, 0], [0, 1, 0]];
_expl3 [[attachTo]] <nowiki>[</nowiki>[[player]], [0.1, 0.1, 0.15], "Pelvis"];
_expl3 = "DemoCharge_Remote_Ammo" [[createVehicle]] [[position]] [[player]];
_expl3 [[setVectorDirAndUp]] [ [0.5, -0.5, 0], [0.5, 0.5, 0] ]; </code>
_expl3 [[attachTo]] [<nowiki/>[[player]], [0.1, 0.1, 0.15], "Pelvis"];
 
_expl3 [[setVectorDirAndUp]] [<nowiki/>[0.5, -0.5, 0], [0.5, 0.5, 0]];
[[Image:Sbomber.jpg|300px]] |= Example 4
<br><!-- needed for the text to display properly with the float…??? -->
|EXAMPLE4=
____________________________________________________________________________________________
____________________________________________________________________________________________


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


Line 59: Line 61:
<dl class="command_description">
<dl class="command_description">
<!-- Note Section BEGIN -->
<!-- Note Section BEGIN -->
<dd class="notedate">Posted on June 6, 2009 - 13:47
<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.
Use [[setPos]] to synchronize the direction of the object in a network game.
Example code:
<code>
_obj [[setDir]] 180;
_obj [[setPos]] [[getPos]] _obj;</code>


<dd class="notedate">Posted on September 17, 2011 - 19:20
<dd class="notedate">Posted on September 17, 2011 - 19:20
<dt class="note">'''[[User:TeaCup|teaCup]]'''<dd class="note">
<dt class="note">[[User:TeaCup|teaCup]]
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>
<dd class="note">
SuitcaseObject [[attachTo]] [FoldingTableObject, [0,0,0]];</code>
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>SuitcaseObject [[attachTo]] [FoldingTableObject, [0,0,0]];</code>
You would expect the suitcase to jump to the pivot point of the table, and stick to it.
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'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.
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.<br>
Dodgy objects when it comes to attaching things to them: most in Objects(small), Objects(signs), all of Objects(helpers) categories, etc..
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.


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


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


<dd class="notedate">Posted on September 25, 2014 - 10:00
<dd class="notedate">Posted on September 25, 2014 - 10:00
<dt class="note">'''[[User:ondrejkuzel|ondrejkuzel]]'''<dd class="note">
<dt class="note">[[User:ondrejkuzel|ondrejkuzel]]
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.
<dd class="note">
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.
 
<dd class="notedate">Posted on September 1, 2016 - 17:54 (UTC)</dd>
<dt class="note">[[User:Demellion|Demellion]]</dt>
<dd class="note">
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.
</dd>
 
<dd class="notedate">Posted on August 13, 2019 - 12:55 (UTC)</dd>
<dt class="note">[[User:R3vo|R3vo]]</dt>
<dd class="note">
When attaching an 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.
</dd>


<!-- Note Section END -->
<!-- Note Section END -->
Line 108: Line 117:


<h3 style="display:none">Bottom Section</h3>
<h3 style="display:none">Bottom Section</h3>
[[Category:ArmA 2: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
 
[[Category:Scripting Commands ArmA2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 2|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Arma 3|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting_Commands_Take_On_Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands Take On Helicopters|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]

Revision as of 01:18, 26 June 2020

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.
Using setDir on an attached object sets its direction relative to the reference object's direction, e.g 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 setPos getPos _attachedObj after setDir to synchronise set direction over the network (see setDir's page for its MP behaviour).
Groups:
Uncategorised

Syntax

Syntax:
object1 attachTo [object2, offset, memPoint]
Parameters:
object1: Object - object to attach
object2: Object - object to attach to
offset: Array - (Optional) format PositionRelative
memPoint: String - (Optional) see ArmA: Selection Translations for czech selections names
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]];

Additional Information

See also:
attachObjectattachedObjectsattachedTowaypointAttachVehiclewaypointAttachedVehiclelightAttachObjecttriggerAttachVehicleattachedObjectdetachsetVectorDirsetVectorUpsetVectorDirAndUpmodelToWorldBIS_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

Notes

Posted on September 17, 2011 - 19:20
teaCup
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'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.
Posted on March 28, 2014 - 16:22
Pixinger77
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;
Posted on 1 Jun, 2014 - 2300
ffur2007slx2_5
(ArmA3 ver 1.20) 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
Posted on September 25, 2014 - 10:00
ondrejkuzel
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.
Posted on September 1, 2016 - 17:54 (UTC)
Demellion
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.
Posted on August 13, 2019 - 12:55 (UTC)
R3vo
When attaching an 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.

Bottom Section