How to move a part towards a point using LinearVelocity

There have been a lot of LinearVelocity tutorials, and due to that I’m going to create a short tutorial on this.

For starters, you want to create a small anchored part at the target, put an attachment in that, and that attachment must be assigned to LinearVelocity’s attachment1.

For attachment0, make an attachment inside the origin part that you want to move, and assign that attachment to LinearVelocity’s attachment1.

You want to set LinearVelocity’s VectorVelocity to:

local positionA=originpartposition
local positionB=targetposition

linearvelocity.VectorVelocity=(positionA-positionB).Unit*speed

If you want some built in physics, you can use lerp to achieve this:

local positionA=originpartposition
local positionB=targetposition

game:GetService('RunService').Stepped:Connect(function()
     linearvelocity.VectorVelocity=linearvelocity.VectorVelocity:Lerp((positionA-positionB).Unit*speed, .05)--.05 can be whatever lerp value you want. The lower the value, the more effect 'physics' will have on it.
end)
4 Likes

is the positionA the attachment? i am really curious

positionA is just any position you want it to be, that’s why they put it as “origin part position”. It could be an attachment if you wanted it to be, but you’d have to use attachment.WorldPosition