ApplyImpulse() only working after Humanoid has Died

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.

Don’t set the .Anchored to false. The HRP.Anchored shouldn’t have anything to do with :ApplyImpulse()

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.

1 Like
HRP:ApplyImpulse(dashDirection * 1000)

or else do it on the client :slight_smile:

Regardless of it being Anchored or not, :ApplyImpulse() still didn’t work in this scenario.

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.

The code runs on the client for Players, but on the server for NPCs.

so the thing lags for the npc and the players? This is weird, because i do the same exact thing for my combat system and it works for npc and plrs

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.

3 Likes

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!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.