Arma 3 Scripting

Command in PhysX

attachChild

Also available as Markdown and JSON, or read the original wiki page.

Description

Attaches a child object to a parent, similar to attachTo but instead of a rigid/forced attachment its using a PhysX joint.

Note

For more information see NVIDIA docs.

Note that the joint parameters XYZ orientations, are according to the localFrame of the joint. swingZ/swingY/twist being Yaw/Roll/Pitch, can be changed if the joint itself is rotated, because the joint rotation moves the whole axis.

Syntax

[parent, child] attachChild [jointType, localFrameParent, localFrameChild, miscFlags, jointDescription]

Parameters:

Returns: Nothing - Do NOT depend on this staying nothing, it might change to be something.

Examples

Example 1

Attach a Quad (varname towbar) to a HEMTT (varName vParent) and another HEMTT (varName vChild) to the Quad. Essentially using the Quad as a "towbar":

_parentPos = [0, -5, 0]; // position on the hemtt
_childPos = [0, 1, -0.2]; // position on the quad

_jointDescription =
[
// Limits
    // Linear
    [], // Default is locked

    // Swing
    // [swing1 yaw, swing2 roll, springParams]
    [
        rad 45, // yaw
        0 // roll
    ],
    // Twist pitch
    // [twistLower, twistUpper, springParams]
    [rad -20, rad 20], // Default is locked

// Drives
    [] // Default are none
];

_params = [
    "6DOFJoint",
    // From [pos,dir,up]
    [_parentPos, _parentPos vectorAdd [0, 1, 0], _parentPos vectorAdd [0, 0, 1]],
    // To [pos,dir,up]
    [_childPos, _childPos vectorAdd [0, 1, 0], _childPos vectorAdd [0, 0, 1]],
    // misc [collisions enabled]
    [false],
    _jointDescription
];

[vParent, towBar] attachChild _params;

_parentPos = [0, -1, -0.2]; // Position on the quad
_childPos = [0, 5, 0]; // Position on the hemtt

_params = [
    "6DOFJoint",
    // From [pos,dir,up]
    [_parentPos, _parentPos vectorAdd [0, 1, 0], _parentPos vectorAdd[0, 0, 1]],
    // To [pos,dir,up]
    [_childPos, _childPos vectorAdd [0, 1, 0], _childPos vectorAdd [0, 0, 1]],
    // misc [collisions enabled]
    [false],
    _jointDescription
];

[towBar, vChild] attachChild _params;

Example 2

Attach a Quad (varname towbar) to a HEMTT (varName vParent) and another HEMTT (varName vChild) to the Quad. But we rotate the axis so that Swing's are Pitch/Yaw and Twist is roll

_parentPos = [0, -5, 0]; // position on the hemtt
_childPos = [0, 1, -0.2]; // position on the quad

_jointDescription =
[
// Limits
    // Linear
    [], // Default is locked

    // Swing
    // [swing1 pitch, swing2 yaw, springParams]
    [
        rad 20, // pitch
        rad 45 // yaw
    ],
    // Twist roll
    // [twistLower, twistUpper, springParams]
    [], // Default is locked

// Drives
    [] // Default are none
];

_params = [
    "6DOFJoint",
    // From [pos,dir,up]
    [_parentPos, _parentPos vectorAdd [0, 0, 1], _parentPos vectorAdd [1, 0, 0]], // Note how the up is pointing right and forward is pointing down, we are rotating the whole joint
    // To [pos,dir,up]
    [_childPos, _childPos vectorAdd [0, 0, 1], _childPos vectorAdd [1, 0, 0]],
    // misc [collisions enabled]
    [false],
    _jointDescription
];

[vParent, towBar] attachChild _params;

_parentPos = [0, -1, -0.2]; // Position on the quad
_childPos = [0, 5, 0]; // Position on the hemtt

_params = [
    "6DOFJoint",
    // From [pos,dir,up]
    [_parentPos, _parentPos vectorAdd [0, 0, 1], _parentPos vectorAdd [1, 0, 0]],
    // To [pos,dir,up]
    [_childPos, _childPos vectorAdd [0, 0, 1], _childPos vectorAdd [1, 0, 0]],
    // misc [collisions enabled]
    [false],
    _jointDescription
];

[towBar, vChild] attachChild _params;

Multiplayer

Important

This command does NOT behave well in Multiplayer.

See also

detachChild · setJointDrivePosition · setJointDriveOrientation · setJointDriveLinearVelocity · setJointDriveAngularVelocity · childAttached · parentAttached