Moving player forward with body position has some weird issues?

function Controller:Dash()
	local movementDirection = workspace.CurrentCamera.CFrame:vectorToObjectSpace(self.CharacterObject.Humanoid.MoveDirection).Unit
	local X = movementDirection.X
	local Y = movementDirection.Y
	local Z = movementDirection.Z
	
	local result
	
	if math.abs(X) > math.abs(Z) then
		result = (X < 0) == true and "left" or "right"
	elseif math.abs(X) < math.abs(Z) then
		result = (Z < 0) == true and "forward" or "back"
	else
		result = "forward"
	end
	
	local root = self.CharacterObject.HumanoidRootPart
	
	local BP = Instance.new("BodyPosition")
	BP.Parent = self.CharacterObject.HumanoidRootPart
	BP.D = 600
	BP.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BP.Position = root.CFrame.LookVector * 10
	game:GetService("Debris"):AddItem(BP, 0.3)
end

Essentially, this:

BP.Position = root.CFrame.LookVector * 10

is sending the player to Vector3.new(0,0,0) it seems, when I print root.CFrame.LookVector * 10, I get these absurd numbers:

-7.3027839660645, -5.4710551466997e-07, 6.8314971923828  -  Client - Controller:274

To get rid of the decimal, you can use math.floor().

BP.Position = math.floor(root.CFrame.LookVector * 10)

You can’t use math.floor on a Vector3 value, my issue doesn’t lie in the decimal point but rather on the incorrectly given number.

You are looking to make the number simpler, or the value it returns isn’t correct?

Setting the BP.Position to the root part’s LookVector is sending me flying away, it’s the same position over and over again so I’m presuming its the center of the map.

1 Like

Oh, I don’t know too much about complex math and stuff, sorry I couldn’t help you and I hope you get you problem solved.

Have a nice day
Grayseon

Instead of doing:

BP.Position = root.CFrame.LookVector * 10

Try doing this:

BP.Position =  BP.Position + root.CFrame.LookVector * 10 

It’s definitely made it smoother but I’m still getting brought to the same position.

BP.Position =  self.CharacterObject.HumanoidRootPart.Position +  self.CharacterObject.HumanoidRootPart.CFrame.LookVector * 5

This worked for me!