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

Cframe too fast. Help making the script slow it down without it being choppy?

Hi,

How would I make this glow slower? Right now it is very fast and I want to slow it down.

platechosen = script.Parent.Parent.Part
targetBrick = game.Workspace.PartV
local a = platechosen.CFrame
local b = targetBrick.CFrame

for i = 0, 1, .5 do
    platechosen.CFrame = a:lerp(b, i)
    wait()
end

Thanks, Antux

1 answer

If I'm understanding your problem correctly, it seems to me that you just want to lengthen the iterations of your for loop. The second argument of lerp is simply just the progression from point A to point B (A being 0, B being 1), so just change the step of each iteration.

local platechosen = script.Parent.Parent.Part
local targetBrick = game.Workspace.PartV
local a = platechosen.CFrame
local b = targetBrick.CFrame
local step = 100 -- Step of your progression. This will count as 1/x per iteration.

for i = 1, step do
	-- This keeps our beginning and destination the same, with more
	-- steps in between. In other words, raising the "frame rate".
	platechosen.CFrame = a:lerp(b, i/step)
	wait()
end

Consider basing the speed of your transition off time?

For now, the duration and speed of your transition depends on your step variant, not a specific amount of time you give it. If however we wanted to base our duration off time, it would be much more convenient and aesthetically pleasing. For a nice smooth transition, you should use BindToRenderStep from RunService, and replace your second argument of lerp with the quotient of how much time has elapsed, and your given duration time. Here's an example:

local RunService = game:GetService("RunService")
local RS_Key = "TweenCFrame" -- Key passed to BindToRenderStep

local PointA = workspace:WaitForChild("PointA")
local PointB = workspace:WaitForChild("PointB")

local function TweenCFrame(Object, Position, Duration)
	-- Get current time stamp
	local Start = tick()
	-- Get starting position
	local Pos = Object.CFrame

	RunService:BindToRenderStep(RS_Key, 2000, function()
		-- Get the difference in time so far
		local Elapsed = tick() - Start
		-- Percentage of time passed relative to given duration
		-- and cap it at '1'
		local Progress = math.min(1, Elapsed / Duration)

		-- If 'Progress' has reached it's total, unbind the 
		-- process.
		if Progress == 1 then
			RunService:UnbindFromRenderStep(RS_Key)
		end

		-- Finally, tween the CFrame given 'Progress'
		Object.CFrame = Pos:lerp(Position, Progress)
	end)
end

TweenCFrame(PointA, PointB.CFrame, 10) -- Tween 'PointA' to PointB's CFrame, in 10 seconds.

Hope this helped, if you have any questions, just let me know!

2 comments

0

"platechosen.CFrame = a:lerp(b, 1/step)", the "1/step" should be "i"

0

Guess I missed that in the edit, thanks for pointing it out.

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