I’m encountering a problem with the knockback system in my combat mechanics. I’ve implemented linear velocity to handle knockback effects, but it appears to be quite laggy, as shown in the video below. The knockback should be smooth, but instead, it feels laggy. I suspect the issue might be related to how the velocity is being applied or updated, but I’m not entirely sure where things are going wrong.
Here is my code if needed.
function Combat.Damage(Player, CharacterHit, Damage)
local Humanoid = CharacterHit:FindFirstChild("Humanoid")
local HumanoidRootPart = CharacterHit:FindFirstChild("HumanoidRootPart")
Humanoid:TakeDamage(Damage)
if Damage == 20 and CharacterHit then
local Attachment = Instance.new("Attachment", HumanoidRootPart)
local LinearVelocity = Instance.new("LinearVelocity", Attachment)
LinearVelocity.MaxForce = math.huge
LinearVelocity.VectorVelocity = HumanoidRootPart.CFrame.lookVector * 100
LinearVelocity.Attachment0 = Attachment
Debris:AddItem(LinearVelocity, 0.25)
end
end