How to move character forward with BodyForce relative to camera

I’m making a custom character movement using BodyForce and I am having some trouble with it.

so this is what I got so far: when the player presses “w” (forward) it does this

while wait() do
--print(WalkForward)
if WalkForward == true then
 -- trying to get direction relative to camera, setting the BodyForce to (0,0,-1000) will move it forward but not by the camera 
	local Direction = game.Players.LocalPlayer.Character.HumanoidRootPart.Position*workspace.CurrentCamera.CFrame.Position
	--game.Players.LocalPlayer:Move(Vector3.new(0, 0, -1), true)
	if not game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("Forward") then
		
	
		local bodyForce = Instance.new("BodyForce")
		bodyForce.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart
		bodyForce.Name = "Forward"
		game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("Forward").Force = Direction -- sets the direction
	else
		game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("Forward").Force = Direction
	end
	
end
end

I am trying to make the player move in the direction of where the camera is facing.
How can I make it so that it can make the BodyForce move in the direction of the camera?

Pls help

I would use BodyVelocity for this instead, because its constant. First, create a vector of the X and Z values of the camera’s look vector like this:

Vector3.new(Camera.LookVector.X,0,Camera.LookVector.Z)

Then, since this is a unit vector, we need to multiply it by some walk speed value like 20 or something to make us go a running speed.

Now we can set the velocity of the BodyVelocity to this. You can tweak the values of the BodyVelocity so you get enough force to move the character correctly without it being so powerful that it will fling when you hit a wall.

1 Like

I like using Body Force because of its physics properties, will this work for body force too?

Also how do you get the Camera’s look vector?

 local Camera = workspace.CurrentCamera

 local Direction = Vector3.new(Camera.LookVector.X,0,Camera.LookVector.Z)* 20

thanks :)))

The same thing applies to whatever method you choose to use. The look vector of the camera is just

Camera.CFrame.LookVector

 local Camera = workspace.CurrentCamera.CFrame
 while wait() do
--print(WalkForward)
if WalkForward == true then
	local Direction = Vector3.new(Camera.LookVector.X,0,Camera.LookVector.Z)*1000
	--game.Players.LocalPlayer:Move(Vector3.new(0, 0, -1), true)
	if not game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("Forward") then
		
	
		local bodyForce = Instance.new("BodyForce")
		bodyForce.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart
		bodyForce.Name = "Forward"
		game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("Forward").Force = Direction
	else
		game.Players.LocalPlayer.Character.HumanoidRootPart:FindFirstChild("Forward").Force = Direction
	end
	--WalkForward = false
end
end

sorry, it doesnt work for me, am I setting the direction correctly?, this just moves the player forward regularly

Doesn’t work for me… (30 charssssss)

Change the camera variable back to workspace.CurrentCamera, and get the camera’s CFrame within the loop. It needs to be constantly updated.

holy smokes your a genius thanks :))))))) :open_mouth:

Sorry to bump this old conversation but what if I wanted to move it to the left or right relative to the camera?