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!

1 Like

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)

1 Like

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.

1 Like

What if you make the duration a little longer

1 Like

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

1 Like