Prevent Character Stuttering With Camera Lerps

Is there any way to prevent the character from shifting relative to the Camera’s position when using CFrame:lerp for camera CFrames?

3 Likes

Lerp is meant to move it part of the distance, not complete distance.

You should either set CFrame directly, or set lerp step to 1, as both of those are exactly the same.

a.CFrame = cf or a.CFrame = a.CFrame:lerp(cf, 1)

1 Like

I would suggest lerping the cframe and storing the alpha you’re using for later… Once the character’s velocity goes down enough you can lower the lerp again.
For example, if the character is moving for long enough keep a lerp of 1 so that the camera will not slow down.

Edit:
I may be misunderstanding how you’re using lerp… If you’re using it to smooth out the camera movements try locking the focus point of the camera to their head. When you lerp the cframe use the Position element of the cframe to construct a new cframe pointing to their head. Example: CFrame.new(LerpedCFrame.p, Head.CFrame.p)

2 Likes

If I were you I wouldn’t use lerp for Camera CFrames, Camera is something that is always supposed to follow the character, should not be left behind.

But if you have a good reason, could you tell us why would you use Lerp for it?

Good luck on your project!

1 Like

Sorry for the late reply.

@Legoracer I want the camera to move only part of the distance. That’s why I’m using lerp. However, I’m pretty sure the stuttering is caused by rounding issues.

@superalp1111 @Hexcede I’m using lerping to create a sense of difference in speed. The faster you move, the farther your camera lags behind.

2 Likes

Uhh, sorry for late reply too… Is your problem solved? If not…
Are you using Scriptable CameraType for that? And are you using RenderStepped to set it?
If it’s RenderStepped I guess it’s some sort of mathematical calculation mistake.

1 Like

Yeah I’m using a Scriptable CameraType and Renderstep. I’m pretty sure it’s just some rounding error related to using lerp. Not much I can do about it ;(

I wouldn’t recommend using lerp. A simple spring would work a lot better and (possibly) fix your problem since the issue most likely comes from your speed script. What you have going on here is definitely not a floating point rounding error, as doubles have about 15 decimal places in precision

Perhaps rounding wasn’t the right word here. What I meant was discrepencies in when the character location updates and when the camera updates.

1 Like

You could try just moving the camera towards the player by a static amount of studs; Then it wouldn’t shake.

local humRoot = <get humanoid root>
local cc = workspace.CurrentCamera
cc.CameraType = Enum.CameraType.Scriptable
local amt = 0.1--0.1 studs every time
game:GetService("RunService").RenderStepped:Connect(function()
     local to = CFrame.new(cc.CFrame.p,humRoot.Position).lookVector
     cc.CFrame = CFrame.new(cc.CFrame.p+(to*amt),humRoot.Position)
end)

Note: It might just be better to offset the camera x studs from the player. You could do this with Humanoid.CameraOffset = Vector3.new(0,10,0)

Hope I could help,
-REALTimothy0812