This might be super simple, but I can’t figure it out. Currently I have it so my character looks where the camera is looking on all axis, how do I make it so the character stays on the ground and rotates only along the Y axis?
while wait() do
local rot = CFrame.new(Character.HumanoidRootPart.CFrame.p) * (Camera.CFrame - Camera.CFrame.p)
Character.HumanoidRootPart.CFrame = rot
end
Don’t set CFrame to rotate the character. This will make you spass out and potentially fling when rotating close to walls. I recommend client-side BodyGyro/AlignOrientation instead.
Get the XZ unit-vector of the camera and use that to form the CFrame rather than the full look-vector
Yeah BodyGyro or AlignOrientation would be better, but here is my solution with cframe anyways.
local SHIFT = math.rad(90) -- math.pi/2
local character = script.Parent
local root = character.HumanoidRootPart
local camera = workspace.CurrentCamera
while wait() do
local lookVec = camera.CFrame.lookVector
local angle = -math.atan2(lookVec.Z, lookVec.X) + SHIFT
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, angle, 0)
end