The goal is for:
A) a part to be moved by the client freely relative to the players rootpart position in any way
B) the part to interact with physics
C) the part to replicate using network ownership
I have two scripts I’ve used to replicate the problem in the simplest way possible.
Spawn a regular part in workspace.
Client script under StarterCharacterScripts:
local part = workspace.Part
part.CanCollide = false
local root = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local bp = Instance.new("BodyPosition")
bp.Parent = part
game:GetService("RunService").RenderStepped:Connect(function()
bp.Position = root.Position
end)
Server script under ServerScriptService:
repeat wait() until game.Players:FindFirstChildWhichIsA("Player")
workspace.Part:SetNetworkOwner(game.Players:FindFirstChildWhichIsA("Player"))
Here’s the result:
Notice the part stuttering/jittering behind? I need that gone while fulfilling the 3 criteria above.
I’ve tried using different bodymovers and directly changing assemblylinearvelocity, same effect. Moving cframe directly fixes it but the part doesn’t interact with physics.
Here’s the same bug in 99 nights.
I’ve been at this for the past 7 hours. All I know is that it has something to do with replication delay.
I genuinely haven’t posted on here for years but im really desperate. Thanks in advance.
RenderStepped runs at the frame rate, often faster than the physics simulation.
That’s why I recommend you use RunService.Heartbeat for physics driven movement. Also limit MaxForce and tune D/P for smoothness.
Instead of either use PreSimulation this will update the behavior right before the physics step such that changes are seemingly instant. I would also recommend using AlignPosition instead of BodyPosition as BodyPosition is deprecated and not receiving further updates. PreSimulation reference AlignPosition reference
This will make it worse. You should use an event that triggers before physics for events that sets properties of physics stuff like body movers or constraints. RenderStepped is fine (not great) but Stepped (now called PreSimulation) is meant for this kind of thing.
When I tested that it only marginally helped the jittering, though. None of the RunService events stopped it entirely.
As a follow up to this I would suggest using AlignPosition without RigidityEnabled. The higher your max force is/the higher your responsiveness is for AlignPosition the more “jittery” it will seem.
Personally, I just tend to set up my own custom lerping systems instead of messing with the physics engine anymore. This way I can pretty easily validate things serverside while it also feels like I have more direct control over velocity caps.