function FpsCamera.OnRotationTypeChanged(q)local r=workspace.CurrentCamera local w=r and r.CameraSubject if w and w:IsA("\072\117\109\097\110\111\105\100")then local B=UserGameSettings.RotationType if B==Enum.RotationType.CameraRelative then w.AutoRotate=false RunService:BindToRenderStep("\070\112\115\067\097\109\101\114\097",1000,function(B)if w.AutoRotate or not w:IsDescendantOf(game)or w.SeatPart and w.SeatPart:IsA("\086\101\104\105\099\108\101\083\101\097\116")then RunService:UnbindFromRenderStep("\070\112\115\067\097\109\101\114\097")return end if r.CameraType.Name=="\083\099\114\105\112\116\097\098\108\101"then return end local E=w.RootPart local v=E and E:IsGrounded()if E and not v then local v=w:GetState()local Z=true if q.InvalidRotationStates[v.Name]then Z=false end if w.Sit and w.SeatPart then local q=E:GetRootPart()if q~=E then Z=false end end if Z then local q=E.Position local w=math.min(.2,(B*40)/3)local v=r.CFrame.LookVector v=(v*XZ_VECTOR3).Unit local Z=CFrame.new(q,q+v)E.CFrame=E.CFrame:Lerp(Z,w)end end if q:IsInFirstPerson()then local B=r.CFrame local E,v=q:GetSubjectPosition(w)if E then local q=E-B.Position B+=q r.CFrame=B r.Focus+=q end local Z=q:GetShadowAngle()local x=B.LookVector:Dot(Z)if x<0 then for q,r in pairs(q.HeadMirrors)do r.CFrame=q.CFrame+Z*9 end end q.MirrorBin.Parent=x<0 and r or nil else q.MirrorBin.Parent=nil end end)else w.AutoRotate=true q.MirrorBin.Parent=nil end end end
-- Called when the user's rotation type is changed.
-- This is a strong indication the user is in first person
-- and needs to have its first person movement smoothened out.

function FpsCamera:OnRotationTypeChanged()
	local camera = workspace.CurrentCamera
	local subject = camera and camera.CameraSubject

	if subject and subject:IsA("Humanoid") then
		local rotationType = UserGameSettings.RotationType

		if rotationType == Enum.RotationType.CameraRelative then
			subject.AutoRotate = false

			RunService:BindToRenderStep("FpsCamera", 1000, function(delta)
				if
					subject.AutoRotate
					or not subject:IsDescendantOf(game)
					or (subject.SeatPart and subject.SeatPart:IsA("VehicleSeat"))
				then
					RunService:UnbindFromRenderStep("FpsCamera")
					return
				end

				if camera.CameraType.Name == "Scriptable" then
					return
				end

				local rootPart = subject.RootPart
				local isGrounded = rootPart and rootPart:IsGrounded()

				if rootPart and not isGrounded then
					local state = subject:GetState()
					local canRotate = true

					if self.InvalidRotationStates[state.Name] then
						canRotate = false
					end

					if subject.Sit and subject.SeatPart then
						local root = rootPart:GetRootPart()

						if root ~= rootPart then
							canRotate = false
						end
					end

					if canRotate then
						local pos = rootPart.Position
						local step = math.min(0.2, (delta * 40) / 3)

						local look = camera.CFrame.LookVector
						look = (look * XZ_VECTOR3).Unit

						local cf = CFrame.new(pos, pos + look)
						rootPart.CFrame = rootPart.CFrame:Lerp(cf, step)
					end
				end

				if self:IsInFirstPerson() then
					local cf = camera.CFrame
					local headPos, headLook = self:GetSubjectPosition(subject)

					if headPos then
						local offset = (headPos - cf.Position)
						cf += offset

						camera.CFrame = cf
						camera.Focus += offset
					end

					local shadowAngle = self:GetShadowAngle()
					local inView = cf.LookVector:Dot(shadowAngle)

					if inView < 0 then
						for real, mirror in pairs(self.HeadMirrors) do
							mirror.CFrame = real.CFrame + (shadowAngle * 9)
						end
					end

					self.MirrorBin.Parent = (inView < 0 and camera or nil)
				else
					self.MirrorBin.Parent = nil
				end
			end)
		else
			subject.AutoRotate = true
			self.MirrorBin.Parent = nil
		end
	end
end
