I have been trying to make a knockback system in my combat game. The thing is, whenever this rush move gets used, everything is okay, apart from how the knockback/linear velocity acts. The knockback should happen from where the player attacking faces, but the enemy usually sinks into the floor a bit, then sort of jolts and instantly teleports a bit forward. I am confused on how to solve this.
Here is what is happening:
Here is the code below:
local collectionService = game:GetService("CollectionService")
coolerMove1Remote.OnServerEvent:Connect(function(client, rushData)
local c = rushData.Character
local enemyPart = rushData.Target.HumanoidRootPart
local enemyHuman = rushData.Target.Humanoid
local hrp = c.HumanoidRootPart
enemyHuman:TakeDamage(20)
local enemyLookVector = hrp.CFrame.LookVector * -1
if rushData.Action == "Rushed" then
c.Humanoid.AutoRotate = false
local lv = Instance.new("LinearVelocity")
local a0 = Instance.new("Attachment")
lv.Attachment0 = a0
lv.Parent = a0
a0.Parent = enemyPart
lv.MaxForce = math.huge
lv.VectorVelocity = enemyLookVector * -75
if rushData.Target then
lv.VectorVelocity = enemyLookVector * -75
coolerMove1Remote:FireClient(client, "TargetFound")
lv:Destroy()
a0:Destroy()
end
task.wait(.2)
enemyPart.CFrame = hrp.CFrame:ToWorldSpace(CFrame.new(0,0,-2))
c.Humanoid.AutoRotate = true
task.wait(.6)
local attachment = Instance.new("Attachment")
attachment.Parent = enemyPart
local lv = Instance.new("LinearVelocity")
lv.Parent = attachment
lv.MaxForce = math.huge
lv.VectorVelocity = enemyLookVector * -60
lv.Attachment0 = attachment
game.Debris:AddItem(attachment, .5)
game.Debris:AddItem(lv,.5)
end
end)
I want to mostly want to understand whether I do not have a basic understanding of linear velocity, because I only just started trying to use linear velocity, so I need help seeing what is causing this problem.