I am trying to turn the HumanoidRootPart on it's relative y axis so it matches the angle of the camera. (For a custom First Person Camera script) I am using :ToWorldSpace to turn the RootPart, but when ever I turn the mouse the body of the character starts to spin out of control. I assume that the problem is that the script is adding to what the rotation already is, instead of just setting it. Here is a snippet of my code:

local AngleX = 0
local AngleY = 0

local YClampMin = -80
local YClampMax = 80

--Change AngleX and AngleY
InputService.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		AngleX = AngleX - input.Delta.X
		
		AngleY = math.clamp(AngleY - input.Delta.Y, YClampMin, YClampMax)
	end
end)

--RenderStepped Update
function UpdateCam()
	char.HumanoidRootPart.CFrame = char.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.Angles(0, AngleX, 0))
end

RunService:BindToRenderStep("Update", Enum.RenderPriority.First.Value, UpdateCam)

Here is what is happening: https://gyazo.com/53219490e454ba5151b5b16d1b8cc2e9

2 comments

0

try doing: HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame, mouse.Hit.P)

0

I only want it to turn on the relative Y axis