Jittery Viewmodel? How do I resolve this?

I am working on a game that has a lantern viewmodel, I am using RunService:BindToRenderStep to update the CFrame of the model.

When I play I get this weird jittery movement result. I’m looking for a smooth linear interpolation but I couldn’t find anything on it. I found posts about people using something called Spring, should I use that?

Code

-- context code
Lantern.DisplayOffset = CFrame.new(1.25, -1, -2)
local Camera = workspace.CurrentCamera

local function update(delta)
	Lantern.Reference:PivotTo(Camera.CFrame * Lantern.DisplayOffset)
end
	
RunService:BindToRenderStep("lantern", Enum.RenderPriority.Camera.Value + 1, update)

Video

Im guessing :PivotTo is less performant than .CFrame try using .CFrame instead.

Is it anchored btw?

1 Like

You might have better luck using a Heartbeat connection to make it look smoother:

-- context code
Lantern.DisplayOffset = CFrame.new(1.25, -1, -2)
local Camera = workspace.CurrentCamera

local function update(delta)
	Lantern.Reference:PivotTo(Camera.CFrame * Lantern.DisplayOffset)
end

game:FindService("RunService").Heartbeat:Connect(update)
1 Like

Im using :PivotTo to move the Model There is no CFrame property on Models
No it’s not anchored.

RunService.Heartbeat still has the same effect

Try RunService.Stepped. Keep in mind that delta time is its second parameter though.

use renderstepped or update before camera.

try a linear tween it may look smoother

FIXED IT
I found a dumb but cryptic solution.
It all had to do with my custom camera script, I found a Smooth Camera script somewhere on the developer forums some time ago, and I rescripted it and made it formatted to work in my game. It all had to with the timing of the updates and extra features.

SmoothCamera.lua

Camera.FieldOfView = SmoothCamera.Settings.FieldOfView
		
if not (Humanoid.MoveDirection == new_Vec()) then
	local Sine = sin(tick() * 12) / 5
	Camera.CFrame *= angles(rad(Sine), rad(Sine), 0)
end

--[[
Before, when I was looking for the solution I attempted to create a shared
variable that stored the CFrame of the camera, so I can access it from my 
lantern script. But I totally forgot at the end of my script, there is a
camera bob function that updates the CFrame of the camera after all of the
variables are updated

so I created an empty function in SmoothCamera to hold the custom function set
in my lantern module. then I pass the new final CFrame to the lantern script
--]]

if SmoothCamera.c__update_fn ~= nil then
	SmoothCamera.c__update_fn(Camera.CFrame)
end

Lantern.lua

function Lantern:init()
	if Lantern.initialized then return end
	Lantern.initialized = true
	
	local function update(cf)
		Lantern.Reference:PivotTo( cf * Lantern.DisplayOffset )
	end
	
	--[[
	i require SmoothCamera from inside the latern module, and i set the function
	to my local update function
	
	when the function fires, it take the CFrame passed through and then apply the
	offset to the Lantern model.
	
	--]]
	
	SmoothCamera.c__update_fn = update
end

Result

Why did I post my solution? I’m positive that people look for solutions for long periods of times and eventually find one where the original poster had the same issue, and then reply’s with “fixed it”. Then you sit there like “:smiling_face_with_tear:

This may not be an exact answer to someone’s exact problem, but It can give clues on where to start
or how to fix it entirely.

In conclusion, I had another script interfering with the Lantern’s update timing and positioning that
made it so jittery. The camera cframe was being over written after the lantern updates. (the camera bob)

bye.

1 Like

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