You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
A basic knockback system using assembly velocity.
- What is the issue? Include screenshots / videos if possible!
For some reason, when both players attack each other, the knockback is so strong that throws the player out of the map. (video below, sorry for low quality)
-
What solutions have you tried so far?
I have tried to set some humanoid states and tried to made it so if the server detected hyperarmor it knocks both players in an opposite direction.
This is the code:
local DealDamageKB = function(self, damage, Hum : Humanoid, Knockback, cframe)
local force = cframe.LookVector * Knockback
local mass = Hum.RootPart.AssemblyMass
local RootPart = Hum.RootPart
local Player = game.Players:FindFirstChild(Hum.Parent.Name) or false
RootPart:SetNetworkOwner(nil)
Hum:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
Hum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
Hum:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
if RootPart.AssemblyLinearVelocity.Y > 0.9 then
print("Capped KB")
force = force * 0.6 -- 0.676196024591872
end
Hum:TakeDamage(damage)
RootPart.AssemblyLinearVelocity = Vector3.new(0,0,0)
RootPart.AssemblyLinearVelocity = mass * force
task.delay(0.1, function()
Hum:SetStateEnabled(Enum.HumanoidStateType.Physics, false)
end)
if Player then RootPart:SetNetworkOwner(Player) end
coroutine.wrap(StunModule.Stun)(Hum, self.Stun)
end
local RandomAnim = function(Hum)
for i,v in pairs(Hum.Animator:GetPlayingAnimationTracks()) do
v:Stop() v:Destroy()
end
Hum.Animator:LoadAnimation(DamagedAnims[math.random(1, #DamagedAnims:GetChildren())]):Play()
end
module.OnTouch = function(self, Hum, cframe, Action)
if not Hum or not self.Character then return end
local EnemyPlayerV = ValuesHandler[Hum.Parent]
local RootPart = self.Character.HumanoidRootPart
if not EnemyPlayerV.Loaded then return end
if EnemyPlayerV.HyperArmor == true then
local force = cframe.LookVector * -10
local Hum = self.Character.Humanoid
local mass = Hum.RootPart.AssemblyMass
local RootPart = Hum.RootPart
local Player = game.Players:FindFirstChild(Hum.Parent.Name) or false
RootPart:SetNetworkOwner(nil)
Hum:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
Hum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
Hum:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
if RootPart.AssemblyLinearVelocity.Y > 0.9 then
print("Capped KB")
force = force * 0.6 -- 0.676196024591872
end
RootPart.AssemblyLinearVelocity = Vector3.new(0,0,0)
RootPart.AssemblyLinearVelocity = mass * force
task.delay(0.1, function()
Hum:SetStateEnabled(Enum.HumanoidStateType.Physics, false)
end)
if Player then RootPart:SetNetworkOwner(Player) end
return
end
if EnemyPlayerV.Blocking.Active then
if self.BlockBreak then
EnemyPlayerV.Blocking.Health = 0
print(EnemyPlayerV.Blocking.Health)
else
EnemyPlayerV.Blocking.Health -= 1
print(EnemyPlayerV.Blocking.Health)
end
return
end
local Knockback = nil
local Damage = nil
if Action == "M1" then
if self.LastM1 then Knockback = self.Knockback.Last else Knockback = self.Knockback.Normal end
Damage = self.Damage
else
Knockback = self.Knockback
Damage = self.Damage/2
end
coroutine.wrap(RandomAnim)(Hum)
DealDamageKB(self, Damage, Hum, Knockback, cframe)
end