Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

script to move a model smoothly from one point to another?

Is there a script to gradually and smoothly move a model from one vector point to another?

2 answers

You can do this by using the Lerp function. See Lerp

This returns a Vector3 linearly interpolated between the original value and the goal value, by the fraction alpha, which should be in between 0 and 1.

So apply this with a for loop and you get something like this:

part = workspace.Part1 --The part you want to move

StartVector = Vector3.new(0, 0, 0) --First vector point

TargetVector = Vector3.new(5, 5, 5) --Goal vector point

for i = 0, 1, 0.01 do --For loop: i should be in between 0 and 1 (we use i as our fraction alpha), we increase it each time by 0.01, so in total you will move your part 100 times
	wait() --Add a little wait so it doesn't instantly move to the desired point
	part.Position = StartVector:lerp(TargetVector, i) --The lerp function
end

This is just a little example, I recommend experimenting with this little example to give you a feel for what this exactly does.

Hope this helps. C:

EDIT:

If you would want if for a model, you can still use Lerp. Just use either the :MoveTo() funciton as Wookey12 pointed out, or SetPrimaryPartCframe if you want to use CFrames.

script would look something like this:

for i = 0, 1, 0.01 do 
	wait()
	model:MoveTo(StartVector:lerp(TargetVector, i))  
end

Another option would be to weld the model together to one part (like you would with tools) and then just animate that part.

3 comments

0

thanks for the idea but I need something for a model, not a part. any other ideas?

0
0

Or as wookey12 pointed out MoveTo() would work identically, with Vector3s. Another option would be to weld the model together to one part and then just move that part.

if you need it for a model, use the ":MoveTo()" event which stores a vector3 value in the parenthesis. then use a for loop to gradually increase/decrease the vector3 axis.

This discussion is preserved as it was. New answers, comments, and votes are closed.