# How can i use CFrame on BodyPosition?

I’m trying to move a character using BodyPosition but its only moving along the X, Y, Z axis and not diagonally etc… Can i somehow use BodyPosition and move my character diagonally?

1 Like

What do you mean by diagonally, do you mean rotation?

Yes im changing the character’s rotation but the position is still moving along the X, Y, Z axis i was wondering if i could make it so the player could move freely without having to stick on these

Do you have any code to show what you’re doing?

I’m making a custom humanoid specifically for my game here’s the code…

I wanted to make it so the position moves relatively to the part’s rotation

Ah, I see what’s going on. I think that’s because you have the force of two axis instead of one when going diagonal. The issue is that you’re fighting against the BodyPosition instead of using it to move the character I think.

Also yes, you can use CFrame as long as you convert to a Vector3 when using BodyPosition .

So to fix that issue, should i use bodyforce instead of bodyposition?

I meant BodyPosition, but BodyForce can be used too. BodyVelocity is probably better than either for your application. But I forget if MoveVector is relative or not. If it isn’t, then BodyVelocity ill work perfectly. Otherwise, you’ll have to adjust for that.

1 Like

Thanks alot, ill try doing what you said converting cframes into vector3 then executing that.

1 Like

If you still need help, I decided to give it a shot myself:

``````local walkSpeed = 16

local T = game:GetService('TweenService')
function tween(o,t,l,s,d)
s = s or Enum.EasingStyle.Linear
d = d or Enum.EasingDirection.InOut
local i = TweenInfo.new(l,s,d)
return T:Create(o,i,t)
end

local UI = game:GetService('UserInputService')
local P = game:GetService('Players')
local p = P.LocalPlayer
local force = Instance.new('BodyVelocity')
force.MaxForce = Vector3.new(math.huge,0,math.huge)
force.Velocity = Vector3.new()
local character = script.Parent
local root = character:WaitForChild('HumanoidRootPart')
local control = require(p:WaitForChild('PlayerScripts'):WaitForChild('PlayerModule')):GetControls()
local humanoid = character:WaitForChild('Humanoid')
local cam = workspace.CurrentCamera
humanoid.WalkSpeed = 0
force.Parent = root

game:GetService('RunService').Stepped:Connect(function()
local rotation = table.pack(cam.CFrame:ToOrientation())
local moveVector = control:GetMoveVector()
local cframe = CFrame.new(root.Position) * CFrame.Angles(0,rotation[2],0) * CFrame.new(moveVector)
local vector = cframe.Position - root.Position
local speed = (walkSpeed / (math.abs(moveVector.X) + math.abs(moveVector.Z))) * 1.4
local look = CFrame.new(root.Position,cframe.Position)
local lookRotation = table.pack(look:ToOrientation())
if lookRotation[2] == lookRotation[2] and moveVector.magnitude > 0 then