AlignOrientation

Show Deprecated

An AlignOrientation attempts to constrain its Attachment0's orientation to the goal orientation, which is determined by Attachment1 or CFrame depending on the Mode.

AlignOrientation Demo

By default, this constraint only applies torque on Attachment0's parent, although it can be configured to apply torque on both attachments. This torque can be limited to a max amount via AlignOrientation.MaxTorque.

Any torque created by AlignOrientation will be applied about the center of mass of the parent of the attachments (or the center of mass of parts rigidly connected to the parents). Also note that if this constraint attaches one part (A) to another part (B) that is anchored or connected to an anchored part (Z), part A will not be locally simulated when interacting with a player.

Primary axis

The behavior of an AlignOrientation is determined by its AlignOrientation.PrimaryAxisOnly property. By default this value is false and an AlignOrientation will work so that the orientation of its Attachment0 exactly matches the orientation of its goal. It will apply torque about all 3 axes to achieve this goal.

If PrimaryAxisOnly is set to true, then the AlignOrientation will only apply torque if the primary axis of its Attachment0 becomes unaligned with the goal. This means that any rotation about the Attachment0's primary axis will not create a torque.

Torque magnitude

The torque used to constrain an AlignOrientation can either be configured or set to the maximum that constraints allow. Whether the torque is configurable is determined by the AlignOrientation.RigidityEnabled property.

When RigidityEnabled is true, the physics solver reacts as quickly as possible to complete the alignment. This is the same scale of force used to align other constraints, such as prismatics when their attachments are misaligned.

When RigidityEnabled is false, then the force will be determined by the MaxTorque, MaxAngularVelocity, and Responsiveness. MaxForce and MaxVelocity are caps to the torque and angular velocity respectively. The actual scale of the torque is determined by the Responsiveness. The mechanism for responsiveness is a little complicated, but put simply the higher the responsiveness, the quicker the constraint will try to reach its goal.

Reaction Torque

AlignOrientations by default only apply a torque on Attachment0's parent Part. The parent Part of Attachment1 remains unaffected. However, a torque can also be applied to Attachment1 by enabling the AlignOrientation.ReactionTorqueEnabled. This will cause a torque to be applied to both Attachment0 and Attachment1 in equal and opposite directions.

Code Samples

Creating an AlignOrientation

1local RunService = game:GetService("RunService")
2
3local part1 = Instance.new("Part")
4part1.Name = "Part1"
5part1.Parent = game.Workspace
6part1.Anchored = true
7part1.Position = Vector3.new(-7, 2, 3)
8
9local part2 = Instance.new("Part")
10part2.Name = "Part2"
11part2.Parent = game.Workspace
12part2.Anchored = false
13part2.Position = Vector3.new(-7, 2, 8)
14
15local attachment0 = Instance.new("Attachment")
16attachment0.Parent = part2
17
18local attachment1 = Instance.new("Attachment")
19attachment1.Parent = part1
20
21local alignOrientation = Instance.new("AlignOrientation")
22alignOrientation.Parent = part1
23alignOrientation.Attachment0 = attachment0
24alignOrientation.Attachment1 = attachment1
25alignOrientation.RigidityEnabled = true
26
27RunService.RenderStepped:Connect(function()
28 part1.CFrame = part1.CFrame * CFrame.Angles(0, 0.05, 0)
29end)

Summary

Properties

The constraint's axis alignment type (parallel or perpendicular).

The goal orientation of the AlignOrientation (the translation component is ignored).

The maximum angular velocity the constraint can use to reach its goal.

The maximum torque the constraint can use to reach its goal.

The way the constraint determines its goal orientation.

The direction of the goal's X-Axis, represented as a unit Vector3.

If true, the AlignOrientation applies torque if the primary axis of its Attachment0 becomes unaligned with the goal.

When true the constraint will apply torque on both Attachments to achieve the goal.

Controls how quickly the constraint will reach its goal. Higher values will cause the attachment to align quicker. Value can be between 5 and 200.

When true, the solver reacts as quickly as possible to complete the alignment. When false, the torque is dependent on MaxTorque, MaxAngularVelocity, and Responsiveness.

The direction of the goal's Y-Axis, represented as a unit Vector3.

Events

Methods

Properties

AlignType

The AlignType specifies the desired relationship between the primary axes of the Attachment0 and the goal. The constraint will try to maintain this relationship by applying forces within specified limits.

This property is visible in Studio and meaningful only when AlignOrientation.PrimaryAxisOnly is set true.

Enums

It can be set to any of the possible AlignType values.

NameValueDescription
Parallel0Two parallel axes
Perpendicular1Two perpendicular axes

CFrame

The orientation of the CFrame determines the goal orientation of the AlignOrientation when its Mode is OneAttachment. The translation component of the CFrame is ignored.

MaxAngularVelocity

The maximum angular velocity the constraint can use to reach its goal.

MaxTorque

The maximum torque the constraint can use to reach its goal.

The Mode specifies the way its constraint determines its goal orientation.

OneAttachment

The constraint attempts to match the orientation of Attachment0 to the orientation of CFrame. Attachment1 is not used.

TwoAttachment

The constraint attempts to match the orientation of Attachment0 to the orientation of Attachment1. CFrame, PrimaryAxis, and SecondaryAxis are not used.

PrimaryAxis

The PrimaryAxis is the direction of the goal's X-Axis, represented as a unit Vector3. This is only used when the AlignOrientation's Mode is OneAttachment.

PrimaryAxisOnly

If true, the AlignOrientation applies torque if the primary axis of its Attachment0 becomes unaligned with the goal. This means that any rotation about the Attachment0's primary axis will not create a torque.

ReactionTorqueEnabled

When true the constraint will apply torque on both Attachments to achieve the goal.

Responsiveness

Controls how quickly the constraint will reach its goal. Higher values will cause the attachment to align quicker. Value can be between 5 and 200.

RigidityEnabled

When true, the solver reacts as quickly as possible to complete the alignment. When false, the torque is dependent on MaxTorque, MaxAngularVelocity, and Responsiveness.

SecondaryAxis

The SecondaryAxis is the direction of the goal's Y-Axis, represented as a unit Vector3. This is only used when the AlignOrientation's Mode is OneAttachment.

Events

Methods