Im using a ragdoll prediction system for my game and the desync is just so bad sometimes, especially when the ither player is jumping. Heres how it works:
the attacking player hits the victim. A remote is fired to the server. The victim’s client does their own physics. Since there is a period of freezing before the physics are applied on the other clients, the other clients predict the players ragdoll. It works fine most of the time, but when the ictim is in midair, the desync starts getting really bad.
(by the way the semi-transparent character is the real version and the solid one is the predicted character)
what ive tried:
-making increasng friction of the baseplate
-reseting velocity before the victim is knocked back
Heres the code for the client side knockback and the prediction:
knockEvent.OnClientEvent:Connect(function(kb, hitCFrame)
local char = plr.Character
char.HumanoidRootPart.CFrame = hitCFrame
char.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0,0,0)
char.HumanoidRootPart.AssemblyAngularVelocity = Vector3.new(0,0,0)
char.HumanoidRootPart.Anchored = true
task.wait()
char.HumanoidRootPart.Anchored = false
char.HumanoidRootPart.CFrame = hitCFrame
char.Torso.AssemblyLinearVelocity = kb
local hum = char.Humanoid
hum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
hum:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
end)
ragdollPredict.OnClientEvent:Connect(function(ragdollCharacter, knockback, originalTime, hitCFrame, plrVictim)
if plr == plrVictim then return end
ragdollCharacter.Archivable = true
local delay = workspace:GetServerTimeNow() - originalTime
local clonedchar = ragdollCharacter:Clone()
clonedchar.Parent = workspace
clonedchar.HumanoidRootPart.CFrame = hitCFrame
for _,v in pairs(clonedchar:GetDescendants()) do
if v:IsA("BasePart") then
v.CollisionGroup = "clientrigs"
end
end
for _,v in pairs(ragdollCharacter:GetDescendants()) do
if (v:IsA("BasePart") or v:IsA("Decal")) and v.Name ~= "collisionpart" and v.Name ~= "HumanoidRootPart" then
v.Transparency = 0.7
end
end
ragdoll.Ragdoll(clonedchar, true)
clonedchar.HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(0,0,0)
clonedchar.HumanoidRootPart.AssemblyAngularVelocity = Vector3.new(0,0,0)
clonedchar.Torso.AssemblyLinearVelocity = Vector3.new(0,0,0)
clonedchar.Torso.AssemblyAngularVelocity = Vector3.new(0,0,0)
task.wait()
clonedchar.HumanoidRootPart.CFrame = hitCFrame
clonedchar.HumanoidRootPart.AssemblyLinearVelocity = knockback
task.wait(2 + delay)
clonedchar:Destroy()
for _,v in pairs(ragdollCharacter:GetDescendants()) do
if (v:IsA("BasePart") or v:IsA("Decal")) and v.Name ~= "collisionpart" and v.Name ~= "HumanoidRootPart" then
v.Transparency = 0
end
if v:IsA("BasePart") then
v.CollisionGroup = "Default"
end
end
end)