Hey guys i'm wanting to move a brick to the postion of another brick smoothly and gradually, i have created the function below to do this.
The issue with it is that the time it takes to move the brick to the other brick always remains the same because of how low wait() gets and roblox cannot wait with such accuracy and it is rounded to 0.
How do you guys suggest i make this work without making the brick movement seem jumpy, by altering the 0.1.
Thanks for any and all suggestions!
local function move(part,point,speed) local distance = (point-part.Position).Magnitude local waitTime = distance/speed local direction = CFrame.new(part.Position, point).lookVector for i = 1, distance, 0.1 do part.Position = part.Position + (direction * 0.1) wait((waitTime/distance) * 0.1) end end move(script.Parent, workspace.End.Position, 10)
Close enough.
CFrame:Lerp()
basically does under the hood what you were attempting to do yourself.
local destination = CFrame.new(20, 0, 20) local start = part.CFrame for i = 0, 1, 0.1 do part.CFrame = start:lerp(destination, i) wait() end
Read more about CFrame:lerp()
here:
http://wiki.roblox.com/index.php?title=CFrame#Methods