How do I set a CFrame smoothly?

Hello, I have been working on an FPS framework but I am strugling with adding a walking animation to the system.

if char.Humanoid.MoveDirection.Magnitude > 0 then
	goalCFrame = goalCFrame * CFrame.new(sin, cos, 0)
else
	goalCFrame = camera.CFrame * gunSettings.OffsetFromCamera
end

Here is what happens:


How do I change the goalCFrame variable smoothly?
Thank you!

To set a CFrame smoothly check out lerping!

Example:

local Part1 = --
local Part2 = --

local dur = 1 — Moving duration

local Part3 = Instance.new("Part", workspace)
Part3.CFrame = Part1.CFrame:Lerp(Part2.CFrame, dur)

I did, but this happens:


Here is my code:

	if char.Humanoid.MoveDirection.Magnitude > 0 then
				goalCFrame = goalCFrame:Lerp(camera.CFrame * gunSettings.OffsetFromCamera * CFrame.new(sin,cos,0), 0.1)

			else
				goalCFrame = goalCFrame:Lerp(camera.CFrame * gunSettings.OffsetFromCamera, 0.1)
			end

I’m sorry but I’m not exactly sure what is happening and what is supposed to be happening, are you talking about the jittering?

1 Like

Yes, it doesnt switch between the animations smoothly.

What if you make the duration a little longer

maybe look into springs and offsets like how the walkcycle works in