Jittering When Lerping Objects Using LocalScript With NetworkOwnership Set To Player

I was looking to make a grab system where a part will hover in front of the camera if the player interacts with it and picks it up.

I was hoping to do it without using constraints, but I’ve run into a heavy jittering problem that pops up when trying to lerp it locally.

With the NetworkOwnership of the held part set to the player picking it up, it looks like this:

And when ignoring NetworkOwnership, it appears smoother until letting go of the part, where it often lags, hangs in the air, or even teleports back to where it was sitting originally:

I was wondering if there was any way to mitigate the stutter/lag when trying to manipulate parts on the client so they don’t go flying or just don’t move.

Here’s the entirety of the working parts of my scripts:

-- LocalScript
mouse.Button1Down:Connect(function()
	local camCF = camera.CFrame
	local grab = workspace:Raycast(camCF.Position, camCF.LookVector*5, grabParams())
	
	if not grabObj and not grab then return end
	-- grabObj is whatever part is currently being held, if any
	
	print(grabObj ~= nil and "Dropping" or "GrabObject Found")
	
	Events.GrabEvent:FireServer(grabObj or grab.Instance, grabObj and 1 or 0)
	
	grabObj = if (grabObj or not grab) then nil else grab.Instance
	
	print(grabObj and grabObj.Name or "Dropped")
	
end)

RunSVC.Heartbeat:Connect(function(delta)
	if not grabObj then return end
	local camCF = camera.CFrame
	grabObj.CFrame = grabObj.CFrame:Lerp(camCF * CFrame.new(0,0,-5), delta*30)
end)
-- ServerScript
grabEvent.OnServerEvent:Connect(function(player, grabObject : BasePart, state : number)
	grabObject:SetNetworkOwner(state == 0 and player or workspace)
	print("Server Ownership of part set to: "..tostring(grabObject:GetNetworkOwner()))
end)

You Should Try Anchoring The Part To Avoid Any Interactions. Unless you want the little physics interactive feature that most games do.

In that case you should try :

Only changing the state when they are actually holding the object

grabObject:SetNetworkOwner(state == 1 and player or nil)

Lowering the lerp speed

grabObj.CFrame = grabObj.CFrame:Lerp(camCF * CFrame.new(0, 0, -5), math.clamp(delta * 10, 0, 1))

If All of those don’t work, I think you might have to try align position and align orientation even though you didn’t want to.

1 Like

Right, the problem is that I would like the held objects to get caught on/interact with other things in the world.

I’ve fiddled with it a bit, and at this point Im thinking it would be best for me to just suck it up and use some sort of constraint setup. I’m thinking of either just using an AlignPosition or giving the player a dedicated part floating in front of them to hook up a high tension spring or something similar to for attaching it to grabbable parts.

I’ve done similar stuff before and was just sorta hoping to find a method that didn’t involve so many individual objects, but I guess that’s the road I must travel, for now. Lol

I broke down and wound up adding an attachment to the grabbable part and using an AlignPosition, there are no longer any issues with lag or stuttering:

local grabber = ReplicatedStorage:FindFirstChild("Grabber") :: AlignPosition

mouse.Button1Down:Connect(function()
	local camCF = camera.CFrame
	local grab = workspace:Raycast(camCF.Position, camCF.LookVector*5, grabParams())
	local blocked = workspace:Raycast(camCF.Position, camCF.LookVector*5, blockedParams())
	
	if not grabObj and not grab then return end
	
	print(grabObj ~= nil and "Dropping" or "PhysObject picked up by "..player.Name)
	
	Events.GrabEvent:FireServer(grabObj or grab.Instance, grabObj and 1 or 0)
	
	grabObj = (grab and not grabObj) and grab.Instance or nil
	
	grabber.Parent = grabObj or ReplicatedStorage
	
	grabber.Attachment0 = grabObj and grabObj:FindFirstChild("GrabAttach") or nil
	
	print(grabObj and (player.Name.." grabbed "..grabObj.Name) or "Dropped")
	
end)

RunSVC.Heartbeat:Connect(function(delta)
	local camCF = camera.CFrame
	grabber.Position = camCF.Position + (camCF.LookVector*5)
end)

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