function module.knockback(targetPart, strength, attacker)
if not targetPart or not targetPart:IsA("BasePart") then return end
if targetPart.Anchored then return end
local character = targetPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local rootPart = character:FindFirstChild("HumanoidRootPart")
local applyTo = rootPart or targetPart
local resistance = humanoid:GetAttribute("knockbackresistance") or 1
if applyTo:GetNetworkOwner() ~= nil then
pcall(function() applyTo:SetNetworkOwner(nil) end)
end
local attackerPos = (typeof(attacker) == "Instance" and attacker:IsA("Model")) and attacker.PrimaryPart.Position or attacker
if typeof(attackerPos) ~= "Vector3" then attackerPos = applyTo.Position - applyTo.CFrame.LookVector end
local diff = (applyTo.Position - attackerPos)
local direction = Vector3.new(diff.X, 0, diff.Z).Unit
local forceDirection = (direction + Vector3.new(0, 0.5, 0)).Unit
applyTo.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
applyTo:ApplyImpulse(forceDirection * strength * resistance)
task.delay(0.1, function()
if not applyTo or not applyTo.Parent then return end
local player = game.Players:GetPlayerFromCharacter(character)
if player then pcall(function() applyTo:SetNetworkOwner(player) end) end
end)
end
return module ```
#is anyone good at knockback?
1 messages · Page 1 of 1 (latest)
My knockback is very inconsistent
if you do not see any problems here it might be my ragdoll script
You define diff, but I can't see where you use it.
Multiply the look vector by something bigger, to increase the knock back giving it some more power