Viewmodel moving when the player camera is not actually moving

I’ve noticed an issue with many Roblox games and my current one. Even if the player looks down while their camera is already at the bottom of the screen, it will still move the ViewModel down.

Current code i’m using with spring module:

=

RunService.RenderStepped:Connect(function(dt)
	InFirstPerson()
	if not Equipped.Value then return end
	----- Viewmodel Movement -----
	local distance = (LocalPlayer.Character.Head.Position - workspace.CurrentCamera.CFrame.Position).Magnitude
	local Delta = UserInputService:GetMouseDelta()
	swayspring:shove(Vector3.new(-Delta.X/2500, Delta.Y/2500, 0))

	local UpdatedSway = swayspring:update(dt)
	local UpdatedBob = bobspring:update(dt)

	if WeaponViewmodel ~= nil then
		WeaponViewmodel:PivotTo(Camera.CFrame * CFrame.new(UpdatedSway.X, UpdatedSway.Y, 0) * CFrame.new(UpdatedBob.X, UpdatedBob.Y, 0))
		bobspring:shove(Vector3.new(Bob(5), Bob(10), Bob(5)) / 10 * (Character.PrimaryPart.Velocity.Magnitude) / 125)
	end
	----- Viewmodel Movement -----
end)

Example video of what im jibber jabbering about: robloxapp-20240808-1323322.wmv (9.4 MB)

I’m turning into pomni over this rn

2 Likes

Instead of using the Mouse Delta to control your Spring, I would recommend getting the rotational delta of the Camera.

local cframe = Camera.CFrame
local deltaX, deltaY = prevCFrame:ToObjectSpace(cframe):ToOrientation()
prevCFrame = cframe

Just make sure to establish the prevCFrame variable outside your RenderStepped function.

This is a better way of doing Viewmodel sway in my opinion, as this works for any type of input, not just Mouse.

Edit: Fixed CFrame math

2 Likes