How would I move a bodyposition to my humanoid's movedirection?

So basically I’m wanting smooth movement when moving but I can’t exactly figure out how to make it work though

Here is what I came up with so far

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")
humanoid.WalkSpeed = 0

local bodyposition = Instance.new("BodyPosition")
bodyposition.MaxForce = Vector3.new(math.huge,0,math.huge)
bodyposition.Parent = root

game:GetService("RunService").Heartbeat:Connect(function(dt)
	local movedir = root.CFrame:VectorToObjectSpace(humanoid.MoveDirection)
	bodyposition.Position = bodyposition.Position + Vector3.new(movedir.Z,0,-movedir.X)
end)
1 Like

Okay I figured it out, I can’t believe it went over my head.

I was using the root’s CFrame to convert the Vector into object space which messed up the directional vectors making them relative to the root cframe.

Sorry If i didnt explain that well.

Updated script:

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")
humanoid.WalkSpeed = 0

local bodyposition = Instance.new("BodyPosition")
bodyposition.MaxForce = Vector3.new(math.huge,0,math.huge)
bodyposition.Parent = root

game:GetService("RunService").Heartbeat:Connect(function(dt)
	bodyposition.Position = bodyposition.Position + Vector3.new(humanoid.MoveDirection.X,0,humanoid.MoveDirection.Z)
end)