I am currently struggling to make an effective/realistic knockback system. When I hit the opponent, they get knockback the opposite way (Foward).
- Below is a video of my current problem
https://gyazo.com/d8ac62d231b52133c2476b2d05fccbc4
Here is my knockback code:
--// I left out some code as I believed they were irrelevant
function GetMassOfModel(model)
local mass = 0
for i, v in pairs(model:GetChildren()) do
if v:IsA('BasePart') or v:IsA('Union') then
mass = mass + v:GetMass()
end
end
return mass
end
--// The instance "Enemy" is the opposing player or npc's character
local Force = 85
local Mass = GetMassOfModel(Enemy) * 5000
local lookDirection = Enemy.HumanoidRootPart.CFrame.LookVector
local knockback = -lookDirection * Force
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Parent = Enemy.HumanoidRootPart
BodyVelocity.MaxForce = Vector3.new(Mass, Mass, Mass)
BodyVelocity.Velocity = Enemy.HumanoidRootPart.CFrame.LookVector * Force
game.Debris:AddItem(BodyVelocity, 0.2)