LinearVelocity or BodyVelocity(depreciated) for making a knockback system

I have a question about making a knockback system using bodyvelocity
I find that bodyvelocity is really good for making a knockback system but its depreciated should I use it?
I tried making a knockback system using Linearvelocity but the result didn’t really go that well
Any suggestions?

2 Likes

I’ve heard it’s better to use BasePart:ApplyImpulse() for a knockback system. I suggest also taking a look at BasePart.AssemblyMass.

3 Likes

Try something like this
boom.hit:connect(function(part)
local look = cframe.look(part pos, explosion pos).LookVector
local ray = workspace:raycast(explosion pos,look)
if ray
easybodyvel.push(10,look,part)
end
end)

i will test it and see if it works

1 Like

is this a new method of baseparts? never heard of

I’m actually not too sure. I’m guessing they were around for a long time or were recently added.

I have a solution to your problem.

local hrp:Part = nil --Author of the knockback (Part)
local targetHRP:Part = nil --Target object (Part)
local strengthKnockback = 15 --Strength Of Knockback (Number)
local front = false
local calc

if front then calc=strengthKnockback end
if not front then calc=(-strengthKnockback) end

targetHRP:ApplyImpulse(hrp.CFrame.LookVector*calc)

If you want on a type of function:

function knockback(author:Part,target:Part,strength:number,isFront:boolean)
	strength = strength or 15
	isFront = isFront or true
	if isFront then target:ApplyImpulse(author.CFrame.LookVector*strength) end
	if not isFront then target:ApplyImpulse(author.CFrame.LookVector*(-strength)) end
end
1 Like

Like what @AustnBlox said, ApplyImpulse is great for moving parts.

If you want to push a player back, then do this.

local speed = 30

BasePart:ApplyImpulse(BasePart.CFrame.LookVector * BasePart:GetMass() * workspace.Gravity * -speed)
1 Like

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