How to convert this BodyVelocity script to BodyForce?

I’m experimenting with my knockback hammer and I don’t think I like how BodyVelocity looks like it’s just lerping so I want to try BodyForce. But I don’t really know how to use it, like, what’s the equivalent of Velocity in BodyForce? How can exert force to a certain direction?

This is what I have so far and I want to replace my BodyVelocity system with BodyForce:

local tool = script.Parent
local head = tool.Handle

local remoteEvent = tool.RemoteEvent

local smash

remoteEvent.OnServerEvent:Connect(function(player, character, charged, magnitude)
	local rootPart = character:FindFirstChild("HumanoidRootPart")
	
	if charged then
		smash = head.Touched:Connect(function(hit)
			local humanoid = hit.Parent:FindFirstChild("Humanoid")
			local hitCharacter = hit.Parent
			local hitRootPart = hitCharacter:FindFirstChild("HumanoidRootPart")
			
			if humanoid then
				local knockback = Instance.new("BodyVelocity")
				
				knockback.Parent = hitRootPart
				knockback.Velocity = (rootPart.CFrame.LookVector * magnitude) + (rootPart.CFrame.UpVector * magnitude)
				knockback.MaxForce = knockback.MaxForce * magnitude
				wait()
				knockback:Destroy()
			end
		end)
		
		wait(0.3)
		smash:Disconnect()
	end
end)

Well, it won’t really work consistently, since wait pauses for an unknown amount of time.
So you’d apply a force for some unknown amount of time and get inconsistent results.

A more consistent approach would be to use the new ApplyImpulse method on the target humanoid, but I’ve never used it and that thread makes it seem like there’s some trickery needed to get it to work with other characters.

That all being said, here’s the “inconsistent” way using BodyForce:

local knockback = Instance.new("BodyForce")
knockback.Force = (rootPart.CFrame.LookVector * magnitude) + (rootPart.CFrame.UpVector * magnitude)
knockback.Parent = hitRootPart
wait() -- sort of a problem, because who knows how long this will take?
knockback:Destroy()

You’ll find that your magnitude value will need to be much, much larger, since you’re applying a force for a very short amount of time.

This also just may not work at all because Humanoids cause all sorts of problems with physics.

1 Like

for some reason, theres no force being applied here…

				local knockback = Instance.new("BodyForce")
				
				knockback.Parent = hitRootPart
				knockback.Force = (rootPart.CFrame.LookVector * 1000) + (rootPart.CFrame.UpVector * 1000)
				wait(1)
				knockback:Destroy()

Maybe the humanoid is preventing it. You could try Humanoid | Documentation - Roblox Creator Hub to Physics or something

would u mind elaborating please???