Hinge/ヒンジ

HingeConstraintは、2つのAttachmentを中心に、1本の軸の周りだけ回転できるようにします。開き戸やレバーに使えます。

動きの例

Studioで試す

新しいBaseplateを開き、ServerScriptService に Script を作って次のコードを入れ、Playで試します。

-- ドアとヒンジ(ちょうつがい)を作成
local door = Instance.new("Part", workspace)
door.Name = "Door"
door.Anchored = false
door.Size = Vector3.new(6, 8, 1)
door.Position = Vector3.new(3.5, 5, 0)

local hinge = Instance.new("Part", workspace)
hinge.Anchored = true
hinge.CanCollide = false
hinge.Size = Vector3.new(1, 8, 1)
hinge.Position = Vector3.new(0, 5, 0)

-- HingeConstraintを作成
local hingeConstraint = Instance.new("HingeConstraint",hinge)
local attachment0 = Instance.new("Attachment", hinge)
local attachment1 = Instance.new("Attachment", door)
hingeConstraint.Attachment0 = attachment0
hingeConstraint.Attachment1 = attachment1

-- アタッチメントの位置と回転方向の設定
attachment0.Position = Vector3.new(hinge.Size.X/2,0,0)
attachment0.Orientation = Vector3.new(0, 0, 90)
attachment1.Position = Vector3.new(-door.Size.X/2,0,0)
attachment1.Orientation = attachment0.Orientation

-- ドアの開閉を90度に制限
hingeConstraint.LimitsEnabled = true
hingeConstraint.LowerAngle = -90
hingeConstraint.UpperAngle = 90

固定した柱と動くドアを、接続点が重なる位置でつなぎます。両方のAttachmentの主軸を上に向けているので、ドアは縦軸を中心に回ります。この例の開閉範囲は、閉じた位置から左右に90度ずつです。

モーターとサーボの設定

ヒンジのActuatorTypeがMotorに設定されている場合、AngularVelocityに到達することを目標にアタッチメントを回転させようとします。この回転はMotorMaxAccelerationとMotorMaxTorqueで制御できます。
ヒンジのActuatorTypeがServoに設定されている場合、TargetAngleで指定された角度まで回転しようとします。この回転はAngularSpeedとServoMaxTorqueの両方で制御されます。

StudioのExplorerからも HingeConstraint と2つのAttachmentを作成できます。

Roblox公式のヒンジの設定ガイド

Roblox公式の HingeConstraint リファレンス

動作を確かめる

Playしてドアを押し、上下や横にずれずに回るか確認します。開く方向や範囲が違う場合はAttachmentのAxis、LowerAngle、UpperAngleを確認します。

パーツをつなぐ制約の一覧に戻る