- What do you want to achieve? Keep it simple and clear!
Hi, I’m trying to script knockback for a fighting game. How the script works is pretty simple:
After getting hit humanoid, the network ownership of it is given to the server, which checks for the Mass of its model, and applies knockback.
- What is the issue? Include screenshots / videos if possible!
The knockback works correctly most of the times, the only issue is that, when you apply the knockback while standing on your victim’s head, the force applied is way to high. (I have no idea why the testers tried to do this ).
Video:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to set the humanoid’s state to physics, and tried to cap the velocity. I’ve also searched on the devHub but can’t find anything related to knockback with assemblyvelocity.
Here’s my code:
local DealDamageKB = function(self, damage, Hum : Humanoid, Knockback, cframe)
local force = cframe.LookVector * Knockback
local mass = self.Character.PrimaryPart.AssemblyMass
local RootPart = Hum.RootPart
local Player = game.Players:FindFirstChild(Hum.Parent.Name) or false
RootPart:SetNetworkOwner(nil)
if RootPart.AssemblyLinearVelocity.Y > 0.9 then
print("Capped KB")
force = force * 0.6 -- 0.676196024591872
end
Hum:TakeDamage(damage)
Hum:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
RootPart.AssemblyLinearVelocity = Vector3.new(0,0,0)
RootPart.AssemblyLinearVelocity = cframe.LookVector * mass * Knockback
if Player then RootPart:SetNetworkOwner(Player) end
coroutine.wrap(StunModule.Stun)(Hum, self.Stun)
end
Thanks to everyone willing to help me.