Rope/ロープ
RopeConstraintは、2つの接続点が指定した長さより離れないようにします。近づいたときはロープがたるむように動きます。
動きの例
Studioで試す
新しいBaseplateを開き、ServerScriptService に Script を作って次のコードを入れ、Playで試します。
-- 2つのパーツを作成
local part1 = Instance.new("Part", workspace)
part1.Anchored = true
part1.Size = Vector3.new(1, 1, 1)
part1.Position = Vector3.new(0, 20, 0)
part1.Name = "Anchor"
local part2 = Instance.new("Part", workspace)
part2.Anchored = false
part2.Shape = Enum.PartType.Ball
part2.Size = Vector3.new(3, 3, 3)
part2.Position = Vector3.new(4, 16, 0)
-- RopeConstraintを作成
local ropeConstraint = Instance.new("RopeConstraint")
ropeConstraint.Parent = part1
ropeConstraint.Attachment0 = Instance.new("Attachment", part1)
ropeConstraint.Attachment1 = Instance.new("Attachment", part2)
ropeConstraint.Length = 10 -- ロープの長さ
ropeConstraint.Visible = true -- ロープの表示
ウインチ
Length は接続点の最大距離です。徐々に巻き取る仕掛けでは WinchEnabled をオンにし、WinchTarget に目標の距離を指定します。巻き取り速度は WinchSpeed、引っ張る力の上限は WinchForce で調整できます。
Roblox公式の RopeConstraint リファレンス
動作を確かめる
プレイすると、球が落ちてロープが張り、その後は支点を中心に揺れます。接続点を近づけることもできます。近づく方向も制限したい場合は RodConstraint を使います。