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

How would one add a dampening effect while setting the camera's CFrame on renderStepped?

I've tried a few thing however my last try was using the TweenService becuase it has a built in "Amount of time it takes" so I could use that to essentially make a dampening effect on camera as it tweens to the new goal. This goal is changed every renderStepped which is why I put the tween creation inside the renderstepped event function; however I see the problem. This is a bit less of finding the problem and more of finding a solution because I already know the problem I'm just not sure what I should do instead. I'm unsure how to go about getting similar results without having the tween inside renderStepped and using the "Time" to delay the camera movement. I have my last attempt below. Also please explain why you up or down vote me.

local tweenInfo = TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local tween = tweenService:Create(camera, tweenInfo, {CoordinateFrame = cframeGoal})

RunService.RenderStepped:Connect(function()
  cframeGoal = CFrame.new(Origin,Target)* CFrame.new(0,Y+2,Z)
  local tween = tweenService:Create(camera, tweenInfo, {CoordinateFrame = cframeGoal})
  tween:Play()
end)

1 answer

I found my solution after having a random thought! For anyone else wondering, here.

game:GetService("RunService").Stepped:connect(function(first, dt)
	local alpha = math.clamp(0.35 * 60 * dt, 0, 1)
	local current = camera.CFrame
	local goal = CFrame.new(Origin,Target)
	camera.CFrame = current:lerp(goal, alpha)
end)

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