How to use apply impulse?

I have a knockback script that uses apply impulse, and it apply force differently to players and npc, pls help
https://i.gyazo.com/bc5481684c94eb500eaddcb717b070d8.mp4

local function getModelMass(model: Model): number
	local mass = 0

	for _, v in ipairs(model:GetDescendants()) do
		if v:IsA('BasePart') then
			mass += v:GetMass()
		end
	end

	return mass
end
local mass = getModelMass(humanoid.Parent)
	local forceToApply = mass*HeavyForce
	local upforce = mass* 40

	humanoid.Parent.HumanoidRootPart:ApplyImpulse(player.Character.HumanoidRootPart.CFrame.LookVector*forceToApply +Vector3.new(0,upforce,0))

If you are going to make a topic like this, at least explain what is wrong and what you want to happen.

All you’ve said is you have a script that knocks players back and it does it differently to NPCs than it does to players.

I already gave the video to what’s going on? I want them to have the same knock back distance

Right, you should’ve said that in the first place.

Evidently, the mass is different. I’d suggest that, if you want everyone to receive the same knockback, you simply hardcode those numbers in, as opposed to using maths to get the mass.

1 Like

Can you give an example code? I have no idea how to achieve what you are talking about :sweat_smile:

Instead of using your local function getModelMass(), just use actual numbers.

local forceToApply = 5
local upforce = 30
6 Likes

The NPC’s mass value may differ than the actual player’s mass thus giving different knock-back results, I’d suggest hardcoding the numbers instead of basing it off of the model’s mass.

1 Like