Align Orientation/向きを揃える
AlignOrientation は、接続点が目標の向きにそろうように回転力を加えます。この制約自体が制御するのは向きです。位置も制御したいときは別の制約を組み合わせます。
動きの例
アームを90度向き直らせる
空のBaseplateを開き、ServerScriptService に Script を作ります。次のコードを入れてプレイします。
local base = Instance.new("Part")
base.Name = "Base"
base.Size = Vector3.new(1, 1, 1)
base.Position = Vector3.new(0, 6, 0)
base.Anchored = true
base.CanCollide = false
base.Parent = workspace
local arm = Instance.new("Part")
arm.Name = "Arm"
arm.Size = Vector3.new(6, 1, 2)
arm.Position = Vector3.new(0, 6, 0)
arm.Parent = workspace
local baseAttachment = Instance.new("Attachment", base)
local armAttachment = Instance.new("Attachment", arm)
baseAttachment.Orientation = Vector3.new(0, 0, 90)
armAttachment.Orientation = baseAttachment.Orientation
local hinge = Instance.new("HingeConstraint")
hinge.Attachment0 = baseAttachment
hinge.Attachment1 = armAttachment
hinge.Parent = base
local direction = Instance.new("Attachment", arm)
local align = Instance.new("AlignOrientation")
align.Mode = Enum.OrientationAlignmentMode.OneAttachment
align.Attachment0 = direction
align.CFrame = CFrame.new()
align.MaxTorque = 10000
align.Responsiveness = 15
align.Parent = arm
task.wait(2)
align.CFrame = CFrame.Angles(0, math.rad(90), 0)
ヒンジがアームの位置を保ちます。プレイして2秒経つと、アームがY軸まわりに90度回ります。OneAttachment の CFrame は向きを指定し、その位置成分は使われません。
別のPartの向きに追従させる場合は Mode を TwoAttachment にし、Attachment1 に目標側の接続点を指定します。位置を目標へ近づけるには AlignPosition を使います。