I am creating a knockback system for a combat game, and I’m trying to use BasePart:ApplyImpulse() to simulate knockback over LinearVelocity. However, the knockback won’t work until AFTER a Humanoid has died.
The Code:
for _,v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") then
v.Massless = true -- Mass for :ApplyImpulse() won't matter
end
end
HRP:SetNetworkOwner(nil) -- Let the Server handle the physics
HRP.Anchored = false -- Make sure it's not anchored
HRP:ApplyImpulse(dashDirection * Vector3.new(1000,1000,1000)) -- dashDirection is the calculated Vector3 Unit between the RootPart of the target and the RootPart of the object that is causing knockback
I also make sure is a player is receiving the knockback, this code will run on the client, and will run on the server if it is an NPC.
You can also ask to view more parts of the script if asked, but this block of code is the pure essentials of the knockback mechanic.
The amount of force to apply on a character when they are standing required is more tremendous than you think. Try amplifying the numbers a little by a factor of 10.
For more precise impulses, try accounting the body mass of every character.
I am aware, but like I said mentioned, it only proceeded to work AFTER the Humanoid has Died, and all the BaseParts in the said Character Model are all set to Massless, so their Mass doesn’t matter when calculating the force needed.
This is very likely to be an issue with the way the default Roblox Character Controller behaves when on the ground. Characters are very resistant to being pushed around like this while on the ground, so to see any noticeable movement, you would need a far greater force applied to the HumanoidRootPart. Alternatively, consider changing the HumanoidStateType to something like Ragdoll. You can read more about HumanoidStateTypes here.
The was only a part of the solution, and I applied this after I put a task.wait() after :ApplyImpulse(), because the following code automatically stops any Humanoid Momentum right after. Thank you for teaching me about the HumanoidState thingies!