Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

0
thanks for the idea but I need something for a model, not a part. any other ideas? WackyTacky432 -5 — 6y
0
Cant you use SetPrimaryPartCFrame for models? http://wiki.roblox.com/index.php?title=API:Class/Model/SetPrimaryPartCFrame blacksmiley0 19 — 6y
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. blacksmiley0 19 — 6y
Ad
Log in to vote
0
Answered by
wookey12 174
6 years ago

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.

Answer this question