Unusual Viewmodel Jittering

After fixing an issue with frames per second affecting the recoil, sway and bobble of my viewmodels, this new weird issue had arisen.

There is an unusual jitterness to the viewmodel, I believe this has to do with the second line of code in this module script:

function module.update(viewmodel, dt, RecoilSpring, BobbleSpring, SwaySpring)
	viewmodel:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame)
	
	for i,v in pairs(viewmodel:GetChildren()) do
		if v:IsA("MeshPart") or v:IsA("Part") then
			v.CanCollide = false
		end
	end

	local Bobble = Vector3.new(GetBobbing(10), GetBobbing(5), GetBobbing(5))
	local MouseDelta = game:GetService("UserInputService"):GetMouseDelta()

	local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

	BobbleSpring:shove(Bobble / 10 * (Character.HumanoidRootPart.Velocity.Magnitude) / 10)
	SwaySpring:shove(Vector3.new(-MouseDelta.X / 75, MouseDelta.Y / 75, 0))

	local UpdatedRecoilSpring = RecoilSpring:update(dt)
	local UpdatedBobbleSpring = BobbleSpring:update(dt)
	local UpdatedSwaySpring = SwaySpring:update(dt)

	viewmodel:SetPrimaryPartCFrame(viewmodel:GetPrimaryPartCFrame():ToWorldSpace(CFrame.new(UpdatedBobbleSpring.Y, UpdatedBobbleSpring.X, 0)))
	viewmodel:SetPrimaryPartCFrame(viewmodel:GetPrimaryPartCFrame() * CFrame.new(UpdatedSwaySpring.X, UpdatedSwaySpring.Y, 0))

	viewmodel:SetPrimaryPartCFrame(viewmodel:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(UpdatedRecoilSpring.X), math.rad(UpdatedRecoilSpring.Y), 0))
	workspace.Camera.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X), math.rad(UpdatedRecoilSpring.Y), math.rad(UpdatedRecoilSpring.Z))
end

Here’s the local script in the gun tool:

RunService.Heartbeat:Connect(function(dt)
	if Viewmodel then
		MainModule.update(Viewmodel, dt, RecoilSpring, BobbleSpring, SwaySpring)
	end
end)

Here’s the jitterness im talking about…

Anything would be helpful, thanks!

I think this jittering is caused by the fact you’re using Heartbeat to fire the update function of the ViewModel.

Looking at roblox’s documentation in the Task Scheduler the RunService.Heartbeat event is fired after all simulations are finished which could be the cause of the delay.

Could you instead try using the RunService.RenderStepped method to fire the update event? Since it is called before frame rendering.

2 Likes

You see, the issue is that when i change it to .RenderStepped, The recoil will depend on the FPS of a player

2 Likes

After messing around with the values and using delta time on some stuff, .RenderStepped does seem to work, thanks, mate!

2 Likes

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