Knockback always moves the dummy to the same direction

I’ve tried BodyVelocity, LinearVelocity, and AssemblyLinearVelocity, all three methods give me the same result.
It just moves the dummy to one single direction


Here are the scripts

Module.Knockback = function(Character, Direction, Duration)
	if not Character then return end
	local LowerTorso = Character:WaitForChild("LowerTorso")
	LowerTorso.AssemblyLinearVelocity = Direction
	task.spawn(function()
		task.wait(Duration)
		LowerTorso.AssemblyLinearVelocity = Vector3.new(0,0,0)
	end)
end
local KnockbackStrength = 10
local KnockupStrength = 0
HitModule.Knockback(Hit.Parent, (Root.CFrame + Root.CFrame.LookVector * KnockbackStrength).Position + Vector3.new(0,KnockupStrength,0), 0.4)

Does anyone know why this is happening?

1 Like

Hi, I would recommend using :ApplyImpulse() on the humanoid root part for something like this. Learn more here: BasePart | Documentation - Roblox Creator Hub

1 Like

I believe its HumanoidRootPart:ApplyImpulse(Direction*Power/Mass)
Correct me if am wrong

2 Likes

AssemblyLinearVelocity = direction * mass * acceleration

maybe change

 (Root.CFrame + Root.CFrame.LookVector * KnockbackStrength).Position + Vector3.new(0,KnockupStrength,0)

to

local direction = character.CFrame.LookVector * Vector3.New(0,1,0)

LowerTorso.AssemblyLinearVelocity = direction  *  LowerTorso.GetMass() * 100
1 Like

It stopped doing knockback with that code

1 Like

I will deeply look into this, thank you.

1 Like

Well, after applying your method Root:ApplyImpulse(Direction), the same thing happens.
He just slides to the right instead of forward

1 Like

I would use a VectorForce object since it allows you to add a force to the Dummy based on its rotation. AssemblyLinearVelocity adds a force to the Dummy based on the world’s rotation, so it will always go in the same direction no matter what since that never changes.

1 Like

vector force keeps applying force continuously without stopping, which makes it unsuitable for knockbacks.

1 Like

Try the player’s HumanoidRootPart’s look vector multiplied by the power.

local Direction = HumanoidRootPart.CFrame.LookVector
1 Like

Well yeah i’ve tried VectorForce, still the same issue. Even with AcuatorRelative to Attachment0 it moves the dummy in one direction

Would I just do Root:GetMass() to get the mass? Like my reply if yes

You would have to do something like this also I made an edit to the previous response.

local Mass = 0

for _,v in pairs(Character:GetDescendants()) do
	if v:IsA("BasePart") then
		Mass += v:GetMass()
	end
end

A BasePart’s AssemblyMass already accounts for all connected masses.

2 Likes

Oh yeah, that’s right! Use the assembly mass instead. Thank you!

1 Like

Hi again, i’m sorry but I’m terrible with Velocities and I’m really confused on how to use it. Can you help me out?
this is my current code.

Module.Knockback = function(Character, Target: Model, KnockbackStrength: number, KnockupStrength: number, Duration: number)
	if not Character or not Target then return end
	local Root = Target:WaitForChild("HumanoidRootPart")
	local Direction = Root.CFrame.LookVector
	Root.AssemblyLinearVelocity = Direction
	task.spawn(function()
		task.wait(Duration)
		Root.AssemblyLinearVelocity = Vector3.new(0,0,0)
	end)
end

It does not do anything right now, but i’m trying to make it work

No worries your good! I mean like this

Module.Knockback = function(Character, Target : Model, KnockbackStrength: number)
	if not Character or not Target then return end

	local TargetRoot = Target:WaitForChild("HumanoidRootPart")
    local AttackerRoot = Character:WaitForChild("HumanoidRootPart")

    local TargetMass = TargetRoot.AssemblyMass
	local Direction = AttackerRoot.CFrame.LookVector

    TargetRoot:ApplyImpulse((Direction*KnockbackStrength)/TargetMass)
end
1 Like

You are doing this ToWorldSpace.
Try doing it ToObjectSpace.

Search the forums since others can explain how to do it in your script better than I can.

If you do a knockback from the side the player shouldn’t just move backward.

Sorry @CyberNinjaScripter, I just read your last post.

2 Likes

Yup, anything I do does not work.
Maybe the issue comes from the line that calls the function?

Hitbox.Touched:Connect(function(Hit)
				if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent  ~= Character then
					if not table.find(Hits, Hit.Parent) then
						AnimationsModule.Play(Hit.Parent:WaitForChild("Humanoid"), 17852123099, 1)
						HitModule.Hit(Hit, Hits, Damage, Config:WaitForChild("StunLength").Value, Character, Player)
	    	---->		HitModule.Knockback(Hit.Parent, Hitbox.Position, 0.3)
						SoundsModule.Play(Root, SFXFolder:WaitForChild("Punches"):WaitForChild("Punch7"):Clone())
						local Attachment = VFXFolder:WaitForChild("Hit"):WaitForChild("Core"):Clone()
						game:GetService("Debris"):AddItem(Attachment, 0.5)
						Attachment.Parent = Hit.Parent:WaitForChild("UpperTorso")
						VFXModule.EmitAll(Attachment)
						print((Hit.Parent:WaitForChild("HumanoidRootPart").Position).Unit * Vector3.new(0,Config:WaitForChild("KnockupDistance").Value,-Config:WaitForChild("KnockbackDistance").Value))
					end
				end
			end)