How to make a part pull towards another part

Hey there, I would like to make a part pull towards another part, like a magnet but only one part attracting towards the other part.

2 Solutions:

  1. Use CFrame:Lerp
for i = 1,10,1 do
wait()
Part.CFrame = Part.CFrame:Lerp(Part2.CFrame, i)
end
  1. Use TweenService
local TweenService = game:GetService("TweenService")

TweenService:Create(HumanoidRootPart, TweenInfo.new(2), {CFrame = Part.CFrame}):Play()

Will gravity affect CFrame:Lerp?

If you freeze the HumanoidRootPart and then Lerp, it shouldn’t

What do you mean by “freeze” exactly?

Anchor The HumanoidRootPart

That’s one of the Only way’s you freeze stuff

1 Like

Buf if you anchor the humanoidrootpart, won’t it do anything?

The Only thing freezing the HumanoidRootPart does is Freeze the Character, Tweening or Lerping simply sets the Position or Orientation of the Character to a Instance

Try this:

local TweenService = game:GetService("TweenService")

TweenService:Create(HumanoidRootPart, TweenInfo.new(2), {CFrame = Part.CFrame}):Play()

Or this:

local TweenService = game:GetService("TweenService")

local Tween TweenService:Create(HumanoidRootPart, TweenInfo.new(2), {CFrame = Part.CFrame})
HumanoidRootPart.Anchored = true
Tween:Play()
Tween.Completed:Connect(function()
HumanoidRootPart.Anchored = false
end)

Ohhh that’s interesting, I thought lerp only works when your part is unanchored, thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.