When Tweening on RenderStepped there is a visible shake

What you can do is manually interpolate the current position/rotation to the goal every frame.
Here is a crude example:

local current = camera.CFrame
local goal = CFrame.new(CameraCFrame.p,CameraFocus.p)
camera.CFrame = current:lerp(goal, 0.5)

There are better ways of doing this imo (using scripted springs) but this works well enough and simulates the same thing that springs would accomplish.

Just :lerp the CFrame every frame.

local alpha = 0.5 -- A value between 0 and 1. 1 is instantaneous. 0 doesn't move at all.
Camera.CFrame = Camera.CFrame:lerp(goal, alpha)
2 Likes

There still is a shake when lerping, much less frequent but still there…

https://i.gyazo.com/e878858e25dd3e20ef74b80b32624c35.mp4

This is a consequence of the part’s CFrame being updated before the Camera’s CFrame, and that the part’s CFrame is dependent on the Camera’s CFrame.

Make sure that the part’s CFrame is updated AFTER the Camera’s CFrame is updated.

Are you sure that the part isn’t causing the issue?

Just from looking at it, it appears the shake kinda happens consistently (starting from like 3 secs) and is more to do with the part.

What XAXA said lol.

The part is the HumanoidRootPart in the character, I’m not changing it’s CFrame.

Try this: instead of connecting the function to :RenderStepped, properly bind it to RenderStep with :BindToRenderStep. That way, you can set its priority.

I’m betting that your character updates at a RenderPriority of 300 (see Documentation - Roblox Creator Hub for more info), so the camera should update at a priority below that. (lower priority values get executed earlier)

RunService:BindToRenderStep(
    "camera"
    Enum.RenderPriority.Camera.Value,
    yourUpdateFunction -- this is the function you would normally connect to :RenderStepped
)
2 Likes

Nope, doesn’t work… Setting the render priority to Camera or lower has the same amount of shake and setting it as Character or above is even worse :face_with_raised_eyebrow:

Perhaps is because of how you’re updating the character?

EDIT: I would also want to know how and when you’re getting CameraFocus

The character is being updated by the core scripts, I haven’t changed them in any way :no_mouth:

CameraFocus is just the CFrame of the camera but 1 stud forward so I could make a CFrame with a Vector3 pos and Vector3 lookAt.

Yeah, after testing this for myself, it seems like Lerping isn’t the way to go if you want to eliminate stuttering. You may have to use springs.

EDIT: (I would also probably keep rotation (“look”) and position separate if I could. Use a spring for position, don’t use one for rotation.)

I’ve already been doing this with BodyGyro and BodyPosition for a while and it worked perfectly, but the problem with that is that you need to have a physical part. I haven’t used springs yet, do they need a physical part or do they only need an attachment?

I don’t mean SpringConstraints, I meant some sort of spring module.

I’ll admit that I barely know what I’m talking about at this point since I’ve only ever used springs for simulating gun recoil and not for camera interpolation. I really didn’t expect your problem to be harder than playing around with :lerp and RenderStepped priorities.

Nope. Springs still jitter.

Hey, I don’t know if this will help as I don’t see a loop in your code, but you don’t need to use loops with TweenService.

The number you put inside of TweenInfo.new should be how long the tween takes.

If it takes longer than that for some reason, Roblox will attempt to just teleport the object to the final position I believe.

This happens when the physics sim and your interpolation code use different time deltas.

Try using the delta from Stepped instead of RenderStepped.

3 Likes

Where do I put the delta? I’ve changed RenderStepped to Stepped and also tried Heartbeat but it came up with the same results.

You know when you lerp you have a value you keep adding to? Add delta to that instead of whatever else you’re adding.

Instead of what I suggested earlier:

local alpha = 0.5 -- A value between 0 and 1. 1 is instantaneous. 0 doesn't move at all.
Camera.CFrame = Camera.CFrame:lerp(goal, alpha)

Multiply the alpha by the dt. Increase alpha by some factor because we’re multiplying it by 1/60 on average. Also clamp it to between 0 and 1 so that it never overshoots when the framerate drops suddenly.

local alpha = math.clamp(0.5 * 60 * dt, 0, 1) -- dt goes here
Camera.CFrame = Camera.CFrame:lerp(goal, alpha)

So this works fine, except I can’t change the alpha to a lower number for some reason and the character still jitters when jumping… :rage:

https://i.gyazo.com/32cdda5b6c1f134357dc700ba59d136f.mp4

The alpha is always 1:

image

I tried it with Heartbeat which gave a variable alpha, but it still jittered.

Edit:

Figured out I can change the alpha by dividing it, but it still has a jitter…

Edit2:

Better gif

https://i.gyazo.com/5295d20e14e162fe69bcf9aa9cfd8bc9.mp4