Line Force(力線)

LineForce は、2つのAttachmentを結ぶ直線に沿って力を加えます。目標が動けば、引っ張る方向も変わります。

動きの例

箱を目標のPartへ引く

空のBaseplateを開き、ServerScriptService に Script を作ります。次のコードを入れてプレイします。

local crate = Instance.new("Part")
crate.Name = "Crate"
crate.Size = Vector3.new(3, 2, 2)
crate.Position = Vector3.new(0, 1.2, 0)
crate.Parent = workspace

local target = Instance.new("Part")
target.Name = "Target"
target.Size = Vector3.new(1, 1, 1)
target.Position = Vector3.new(16, 1.2, 8)
target.Anchored = true
target.CanCollide = false
target.Parent = workspace

local pull = Instance.new("LineForce")
pull.Attachment0 = Instance.new("Attachment", crate)
pull.Attachment1 = Instance.new("Attachment", target)
pull.InverseSquareLaw = false
pull.ApplyAtCenterOfMass = true
pull.Magnitude = 1200
pull.Parent = crate

task.wait(0.7)
pull.Enabled = false

箱は目標の方向へ引かれます。目標のZ座標の符号を変えて、引かれる方向を見比べます。力の向きは接続点の位置で決まります。

InverseSquareLaw をオンにすると、同じ設定でも離れるほど力が弱くなり、近づくほど強まります。目標の位置で停止させる仕掛けには AlignPosition を使います。

Roblox公式のLineForce API

パーツの力・速度・位置・向きの一覧に戻る