Why doesn't bodyforce push the player at all?

So basically I added a bodyforce and I use this function to create the bodyforce, and set the bodyforce’s force to parameter 1 of this function:

if uis:IsKeyDown(Enum.KeyCode.W) then
	dash(Vector3.new(0,0,50) * 50,rot)
end
if uis:IsKeyDown(Enum.KeyCode.S) then
        dash(Vector3.new(0,0,-50),rot)
end
if uis:IsKeyDown(Enum.KeyCode.D) then
	dash(Vector3.new(50,0,0),rot)
end
if uis:IsKeyDown(Enum.KeyCode.A) then
	dash(Vector3.new(-50,0,0),rot)
end

But it won’t do anything at all unless I literally spam the key. My player doesn’t move forwards at all as I clearly parent the bodyforce into the root. Here is the function:

local playerDashed = false
function dash(pos,rot,lv)
	if playerDashed then return end
	playerDashed = true
	local char = yourPlayer.Character
	local root = char:FindFirstChild("HumanoidRootPart")
	if root and pos then
		local vel = Instance.new("BodyForce",root)
		vel.Force = pos
		game.Debris:AddItem(vel,10)
	end
	playerDashed = false
end
1 Like

try making the player jump slightly right before the dash.

1 Like

Doesn’t work unless I press space

You are assuming that the body you are applying a force on has a mass of 1. In this case acceleration = force. Since F = ma or Force = mass x acceleration you want to set the force to the acceleration times the mass of the body. To get the mass of the body you can use this function:

local function getMass(model)
    local mass = 0

    for _,descendant in ipairs(model:GetDescendants()) do
        if descendant:IsA("BasePart") and descendant.Massless == false then
            mass = mass + descendant:GetMass()
        end
    end
    
    return mass
end

So in your case you want to set the force like so

vel.Force = getMass(char) * pos

Yeah that does the trick except now it doesn’t launch in the direction I want it to go.
W = Forwards
A = Left
S = Backwards
D = Right

It always launches in 1 specific direction for no reason.

Do you want the forward direction to be based on where the camera is facing or what?

I want it to launch the players root direction. Why?

So forward would be where the HumanoidRootPart is facing?

Use bodyvelocity for .3 seconds with high power instead of body force.
Works much better I’ve tried.

I want to be able to aim where my character is going though.

Like If I’m going forwards I can hold a and it will slightly move me to the left if someone goes that way so I can attack.

Yes the root’s front surface is the forwards position in this case.

local forward = (root.CFrame.LookVector * Vector3.new(1, 0, 1)).Unit
local backward = -forward
local right = (root.CFrame.RightVector * Vector3.new(1, 0, 1)).Unit
local left = -right

You can get the directions based on the root part like so.

So instead of using Vector3.new(0, 0, 50) to go forward you actually just want to do:

local FORCE = 50
local forward = (root.CFrame.LookVector * Vector3.new(1, 0, 1)).Unit
local force = mass * (forward * FORCE)

It’s back to the old problem where you have to jump now just to force yourself in the direction. Here’s the newer code.

if uis:IsKeyDown(Enum.KeyCode.A) then
	dash((-yourRoot.CFrame.RightVector*Vector3.new(1,0,1).Unit),rot)
end
function dash(pos,rot,lv)
	if playerDashed then return end
	playerDashed = true
	local function getMass(model)
	    local mass = 0
	
	    for _,descendant in ipairs(model:GetDescendants()) do
	        if descendant:IsA("BasePart") and descendant.Massless == false then
	            mass = mass + descendant:GetMass()
	        end
	    end
	    
	    return mass
	end
	local char = yourPlayer.Character
	local root = char:FindFirstChild("HumanoidRootPart")
	if root and pos then
		local vel = Instance.new("BodyForce",root)
		local mass = getMass(char)
		vel.Force = mass*(pos*force)
		game.Debris:AddItem(vel,1)
	end
	playerDashed = false
end

what is the force variable here? is it too small?

it’s set to 1000 for the force variable

You can use the CFrame:VectorToObjectSpace() method to add the Vector in ObjectSpace and get what Position that’d be.

For example:

local RootCFrame = char:GetPrimaryPartCFrame()
local Forward = RootCFrame:VectorToObjectSpace(Vector3.new(0, 0, 50))