object.attach_to

This function attaches the context object to a given basis object. The context object will be moved to the basis object's position plus the supplied offset before the attachment is performed; an argument allows you to control whether the offset is relative to the rotation of the basis object. Note that the context object will not be rotated before the attachment is performed.

Attached objects effectively take on Phased physics; their movement cannot be impeded by other objects. Additionally, if objects are attached to a non-solid basis, such as a Flag Stand, then they themselves stop being solid; and if they are attached to an invisible basis, such as a Hill Marker, then they stop being visible altogether. Note that non-solid vehicles still offer entry prompts.

Arguments

basis

The object to attach this one to.

x

The X-coordinate to anchor this object at, relative to the position of the other object. Allowed values are integer constants between -128 and 127, inclusive, where 10 is equal to one Forge unit.

y

The X-coordinate to anchor this object at, relative to the position of the other object. Allowed values are integer constants between -128 and 127, inclusive, where 10 is equal to one Forge unit.

z

The X-coordinate to anchor this object at, relative to the position of the other object. Allowed values are integer constants between -128 and 127, inclusive, where 10 is equal to one Forge unit.

reference_frame

Either the word relative, indicating that the position offset passed to this function is relative to the rotation of the basis object, or the word absolute, indicating that the position offset passed to this function uses the world axes.

Example

alias basis = global.object[0]
current_object.attach_to(basis, 0, 0, 20, relative)

Notes

Anchoring

Objects appear to be attached to the nearest node on a basis object's 3D model, with no apparent distance limit. For example, this piece of code would create a skull and anchor that skull to a Warthog's steering wheel:

alias some_warthog = ...
--
global.object[0] = some_warthog.place_at_me(skull, none, none, 0, 0, 0, none)
global.object[0].attach_to(some_warthog, 0, 0, 20, relative)

Even though the skull is attached to a point two full Forge units above the Warthog, it still attaches to the nearest node in the Warthog's 3D model, which happens to be the steering wheel. If a player enters the driver's seat and turns to the left or right, the skull will move and rotate in an arc above them, in synch with the steering wheel. Different offsets would anchor the skull to other nodes in the Warthog's 3D model, such as its tires.

Most objects have a node defined at their origins, and that can be used to avoid this behavior: spawn an extra object, have it copy the rotation of the basis, and then attach it to the basis with offset (0, 0, 0); then, attach the rest of your objects to that extra object.

Effects of attaching vehicles to other objects

Attaching a vehicle to an object will lock the vehicle in place. The pilot will be able to look around at any angle, but the vehicle will not turn, and the vehicle's weapons fire will be constrained to the weapon's turn radius.

Attached vehicles will not play any entry/exit animations (e.g. a Banshee's canopy opening and closing), but will instantaneously update to any animations' end states when detached (e.g. a Banshee's canopy will instantly snap open or closed as appropriate).

Bipeds in an attached vehicle will lose most animations. Passengers' hands may move slightly (and incorrectly) while reloading their weapon; though they have no reloading or weapon swap animations, appropriate sounds still play, and they cannot fire their weapons while the reload animation would be taking place. Some animations have player model jiggle physics; these jiggle physics remain functional even though the rest of the animation does not.

If a Banshee is performing an evasive maneuver at the moment it is attached, the maneuver will end instantly; no such maneuvers can be performed once the vehicle is attached.

Other notes

See also