CFrame isnt Lerping while not moving

Making an FPS viewmodel system here
My code binds a function to render step

It creates a realistic bobbing effect by taking the number from tick() and putting it in a sine and cosine wave while moving.

The problem is, while not moving, I’d like the viewmodel to smoothly go back to its default position.
But instead it just seems to do nothing when I try to lerp it.

I’m using the Humanoid.MoveDirection.Magnitude to determine if the player is moving or not.

Is the alpha too small? Am I missing something? Should I come at this differently?
Any help and ideas appreciated

Code below
(for clarity, the Viewmodel variable is simply a model that is parented to workspace by a local script)

local BobOffset = CFrame.new()


local function CalibrateViewModel(Delta)
	

	--Bobbing
	if Humanoid.MoveDirection.Magnitude > 0 then
		BobOffset = CFrame.new(math.cos(tick() * 5) * 0.2, math.sin(tick() * 10) * 0.14, -Humanoid.CameraOffset.Z/3)
	else
		--BobOffset = CFrame.new(0, -Humanoid.CameraOffset.Y/3, 0)
		BobOffset:Lerp(CFrame.new(0, -Humanoid.CameraOffset.Y/3, 0), 0.7)
	end
	


	Viewmodel:PivotTo(
		Camera.CFrame * BobOffset
	)
	
end

-- Start
RunService:BindToRenderStep("Test_ViewModelCalibrate", 301, CalibrateViewModel)

I’ll post a video example soon

Video example, its not lagging, thats how it looks ingame.

Lerping a variable doesn’t set that lerped value as the variable’s value.
For example:

local a = Vector3.new(1, 0, 0)
local b = Vector3.new(0, 1, 0)

a:Lerp(b, 0.5)
print(a) -- Outputs: 1, 0, 0

a = a:Lerp(b, 0.5)
print(a) -- Outputs: 0.5, 0.5, 0

So you’ll want to actually set BobOffset to the lerped value too

2 Likes

This worked!
Thank you so much, I had no idea about this regarding lerping.

Again, thanks and have a great day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.