[SOLVED] My custom character rotation is a little buggy


I’m trying to make a system where whenever a player is under water, their rotation matches their camera rotation. Only issue right now is it’s multiplying the current CFrame by the camera angle CFrame, and I’m not sure how to make it so it just simply matches the camera rotation.


Here’s the code :

local cf = Camera.CFrame - Camera.CFrame.Position
Root.CFrame = Root.CFrame*cf

Any help is appreciated. Thanks.

Try something like this:

-- First, turn off auto rotate in the humanoid (I'm assuming you can get a reference to this since you have the root)
humanoid.AutoRotate = false

-- Then setup a function that constantly sets the camera rotation
RunService:BindToRenderStep("LockRotationToCamera", Enum.RenderPriority.Character.Value, function()
    -- Lock the mouse to the center
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
    -- Get the camera rotation as Euler angles, then we'll just use the y
	local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
    -- Set the root's frame to its position and the cameras rotation
	root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0)

More info here:

1 Like

I did some more experiments and figured out the same method on my own by the time I checked back here, but thank you anyway!

I’ll mark it as the solution for others.