Lerp is acting strange

Hi, I’m having some issues with CFrame:Lerp(), and I can’t figure out what I did wrong. I am trying to make a simple top down camera of a ball, and use :Lerp() to make it smooth. I’m using a local script that is requiring a module script to change the camera. When I enable the lerping, the camera faces a strange direction and goes to a different position compared to if I set the camera directly without :Lerp(). Heres my code:

Module Script:


function module:SetCFrame(CFrameAbove, Smoothing, FrameCut)
	
	local player = game.Players.LocalPlayer
	local camera = workspace.CurrentCamera

	if FrameCut == false then
		camera.CFrame = camera.CFrame:Lerp(CFrameAbove,Smoothing)
	else
		camera.CFrame = CFrameAbove
	end
	
end

return module

Local Script:

local module = require(game.ReplicatedStorage.ModuleScript)

game:GetService("RunService"):BindToRenderStep("CameraUpdate",Enum.RenderPriority.Character.Value,function()
	
	local CFrameAbove = CFrame.new(workspace.Ball.Position + Vector3.new(0,20,0)) * CFrame.Angles(math.rad(-90),0,0)
	
	module:SetCFrame(CFrameAbove,.02,true)
	
end)
1 Like

There is a simple solution to this; you don’t need to necessarily re-invent the wheel, rather, you should use what is given to you. You can already make use of ROBLOX’s integrated lerp function for CFrames, I would strongly suggest making use of that instead of creating your own sort of system. I didn’t fully gauge what you’re asking, but I am trying to give the best advice I can right now. Here are the certain parameters that go into this function.

Camera.CFrame:lerp( CFrame goal, number alpha);

If at any point I did misunderstand this, try to explain your problem a bit more precisely, I apologize, and good luck! :smiley:

I am using roblox’s integrated lerp function to smooth out the camera tracking the ball. But for some reason, the lerped camera CFrame is different from the target CFrame after it is settled. The module script is just being used so I can organize my scripts.

I see. Could this be due to the fact that the final position you’re looking for is changing? For instance, if you called it, then the camera moved, the final position would be called to that position, but not to the camera’s actual position? Can I see an example of the issue via a gif or video of sorts so I can furthermore grasp what’s going on?

1 Like

I figured it out, it’s because my camera type was set to fixed instead of scriptable. :sweat_smile:
Thanks for trying to help anyways lol

Ah… That’s okay, lol. Glad you figured it out.