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

How can i gradually move a brick?

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)

1 answer

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

and here: http://wiki.roblox.com/index.php?title=Lerp

3 comments

0

Even after fixing your code, this is too fast and if i increase the wait its too jumpy.

0

Oh, I see. I forgot the 'do' keyword. Yeah, I often do that mistake. Plus, I was kind of in a rush. Updated my answer.

0

For an even smoother transition, you can also lower the third value of the 'for' loop.

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