Character rotates while mouse locked

  1. What do you want to achieve?
    I just want my third person camera to work properly.

  2. What is the issue? The Character rotates when it gets touched by something

3.I’ve tried to fix it myself but and to search the issue online but that didn’t help aswell.

robloxapp-20230118-1301509.wmv (1.7 MB)

Script: (Not mine)

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable


local char = script.Parent

local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = false

local hrp = char:WaitForChild("HumanoidRootPart")

local x = 0
local y = 0

local offset = Vector3.new(3, 3, 10)

uis.InputChanged:Connect(function(input, processed)

	if processed then return end

	if input.UserInputType == Enum.UserInputType.MouseMovement then

		x = x - input.Delta.X

		y = math.clamp(y - input.Delta.Y*0.4, -75, 75)

		hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
	end
end)


game:GetService("RunService").RenderStepped:Connect(function()

	uis.MouseBehavior = Enum.MouseBehavior.LockCenter


	local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
	local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
	local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))

	camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
	
end)

Greetings, Shadow!

  1. I just want my third person camera to work properly.
    Technically, I found a solution for this. I see the code: uis.MouseBehavior = Enum.MouseBehavior.LockCenter. Simply remove the line! The problem should be fixed!

  2. The Character rotates when it gets touched by something
    To fix this, simply remove the code: humanoid.AutoRotate = false. Then the problem should be fixed.
    AutoRotate sets whether or not the Humanoid will automatically rotate to face in the direction they are moving in.

If you have any problem, dont hesitate the ask me :sparkles:

Didn’t work the camera works like the default now, I wanted the character to be locked like a shift lock without it getting rotated when it get touched by something, I apprichiate the Idea tho!

  1. The Character rotates when it gets touched by something
    To fix this, simply remove the code: humanoid.AutoRotate = false . Then the problem should be fixed.
    AutoRotate sets whether or not the Humanoid will automatically rotate to face in the direction they are moving in.

Yeah it got back to the default movement, I want it to rotate with the camera
robloxapp-20230118-1344194.wmv (942.9 KB)

I think this can help, I got this code from another article that I read before.

Article: How to Force Enable Shift-Lock (Without changing the PlayerModule)

local _, y = workspace.CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ() --Get the angles of the camera
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0,y,0) --Set the root part to the camera's rotation

Remember to set the autorotate to false in the humanoid when you use that script!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.