Currently I have a tool that knocks back a player on hit. However, I noticed the knock back is very inconsistent and isn’t very fluid. Their is a ton of velocity fluctuation and the knock back is just wonky.
here is my current script I’m using
local part = script.Parent
function onTouch(hit)
if hit.Parent == nil then return end
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
print"player"
local player = hit.Parent.HumanoidRootPart
if not hit.Parent.HumanoidRootPart:FindFirstChild("BodyVelocity") then
local bv = Instance.new("BodyVelocity", player)
bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bv.P = 500
bv.Velocity = script.Parent.CFrame.LookVector*50
wait(0.2)
bv:Destroy()
end
end
end
part.Touched:Connect(onTouch)
What are some other methods I can do to make a better system? Or how can I improve on my current system?