I need help with an interaction with DragDetectors and Scriptable Camera types

My problem is that when I activate a DragDetector (by clicking and holding), I am no longer able to rotate my camera around, essentially making the DragDetector functionless, unless I physically shimmy my character. I suspect it’s because I have a custom camera script in my game that uses the Scriptable camera type.

I have this function in a localscript that handles setting up the Camera inside the StarterCharacterScripts, It also boasts support for mobile users and console players as well. It holds the functionaltiy for sprinting for players and what happens when their stamina is depleted. I have no clue as to what’s preventing my camera from moving only while clicking and holding onto DragDetectors (And possibly other instances such as press to hold ProximityPrompts).

NOTE: I’ve tried changing the camera type to anything else and it results in the camera being out of place (inside the players head), unable to rotate, or frees the mouse somehow.

function CameraSetup()
	repeat task.wait() until workspace.CurrentCamera
	local Camera = workspace.CurrentCamera
	
	local CameraPosition, TargetCameraPosition
	local AngleX, TargetAngleX = 0, 0
	local AngleY, TargetAngleY = 0, 0
	
	local Running = false
	_G.freemouse = false
	local DefFOV = FieldOfView
	
	local W, A, S, D, LeftShift = false, false, false, false, false
	
	local mi = 0
	local function OnInputChanged(InputType, GameProcessed)
		if GameProcessed == true then
			return
		end
		
		if InputType.UserInputType == Enum.UserInputType.MouseMovement then
			local Delta = Vector2.new(InputType.Delta.X / Sensitivity, InputType.Delta.Y / Sensitivity) * Smoothness
			
			local X = TargetAngleX - Delta.Y
			TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
			TargetAngleY = (TargetAngleY - Delta.X) % 360
		elseif InputType.UserInputType == Enum.UserInputType.Gamepad1 then
			local X = InputType.Delta.X
			local Y = InputType.Delta.Y
			
			local XX = InputType.Position.X
			local YY = -InputType.Position.Y
			
			if abs(XX) < 0.3 and abs(YY) < 0.3 then
				return
			end
			
			mi += 1
			local lmi = mi
			
			if InputType.Position.X > 0 and X < 0 then
				X = 0
			elseif InputType.Position.X < 0 and X > 0 then
				X = 0
			end
			
			if InputType.Position.Y > 0 and Y < 0 then
				Y = 0
			elseif InputType.Position.Y < 0 and Y > 0 then
				Y = 0
			end
			
			local Delta = (Vector2.new(XX / Sensitivity, YY / Sensitivity) * Smoothness) * 0.585
			Delta *= 50
			
			repeat
				local X = TargetAngleX - Delta.Y
				TargetAngleX = ((X >= 80 and 80) or (X <= -80 and -80) or X)
				TargetAngleY = ((TargetAngleY - Delta.X) % 360)
				
				task.wait()
			until mi ~= lmi or abs(InputType.Position.X) < 0.05 and abs(InputType.Position.Y) < 0.05
		elseif InputType.UserInputType == Enum.UserInputType.Touch and GameProcessed == false then
			local Delta = Vector2.new(InputType.Delta.X / Sensitivity, InputType.Delta.Y / Sensitivity) * Smoothness
			Delta *= 5
			
			local X = TargetAngleX - Delta.Y
			TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X 
			TargetAngleY = (TargetAngleY - Delta.X) % 360 
		end
	end
	
	UserInputService.InputChanged:Connect(OnInputChanged)
	
	local function OnInputBegan(InputType, GameProcessed)
		if InputType.KeyCode == Enum.KeyCode.ButtonL3 then
			if W == false then
				W = true
			end
			LeftShift = true
		end
		
		if InputType.UserInputType == Enum.UserInputType.Keyboard then
			if InputType.KeyCode == CanToggleMouse.ActiviationKey then
				if CanToggleMouse.Allowed and _G.freemouse == false then
					_G.freemouse = true
				else
					_G.freemouse = false
				end
			end
		end
		
		if InputType.KeyCode == Enum.KeyCode.W then
			W = true
		end

		if InputType.KeyCode == Enum.KeyCode.A then
			A = true
		end

		if InputType.KeyCode == Enum.KeyCode.S then
			S = true
		end

		if InputType.KeyCode == Enum.KeyCode.D then
			D = true
		end

		if InputType.KeyCode == Enum.KeyCode.LeftShift then
			LeftShift = true
		end
	end
	
	UserInputService.InputBegan:Connect(OnInputBegan)
	
	local function OnInputEnded(InputType, GameProcessed)
		if InputType.KeyCode == Enum.KeyCode.ButtonL3 then
			LeftShift = false
		end
		
		if InputType.KeyCode == Enum.KeyCode.W then
			W = false
		end

		if InputType.KeyCode == Enum.KeyCode.A then
			A = false
		end

		if InputType.KeyCode == Enum.KeyCode.S then
			S = false
		end

		if InputType.KeyCode == Enum.KeyCode.D then
			D = false
		end

		if InputType.KeyCode == Enum.KeyCode.LeftShift then
			LeftShift = false
		end
	end
	
	UserInputService.InputEnded:Connect(OnInputEnded)
	
	local function MobileCheck()
		if UserInputService.KeyboardEnabled == false and UserInputService.TouchEnabled == true then
			local MobileUI = Player:WaitForChild("PlayerGui"):WaitForChild("MobileUI")
			local SprintButton = MobileUI:WaitForChild("SprintButton")

			local function OnMouseDown()
				LeftShift = true
			end

			SprintButton.MouseButton1Down:Connect(OnMouseDown)

			local function OnMouseUp()
				LeftShift = false
			end

			SprintButton.MouseButton1Up:Connect(OnMouseUp)
		end
	end

	task.spawn(MobileCheck)

	local sprinting = false
	local depletedStamina = false
	
	ToggleBlur(false)

	local function HandleSprintStateChange()
		if (ReplicatedStorage.ActiveChallenges:FindFirstChild("slowPlayer")) then return end
		if RunTime <= 0 then
			sprinting = true
			depletedStamina = true 
		else
			sprinting = false
			if depletedStamina then
				ToggleBlur(false) -- Disable blur if stamina was just regained
				depletedStamina = false -- Reset the flag
			end
		end
	end

	RunService.Heartbeat:Connect(HandleSprintStateChange)

	
	local function OnRenderStepped(DeltaTime)
		if _G.VideoCamera == true then
			return
		end

		UpdateCharacter()

		-- Update camera position smoothly
		CameraPosition = Camera.CFrame.Position
		TargetCameraPosition = Camera.CFrame.Position

		CameraPosition = CameraPosition + (TargetCameraPosition - CameraPosition) * 0.28
		AngleX = AngleX + (TargetAngleX - AngleX) * 0.35

		-- Calculate the shortest path for rotation
		local Distance = TargetAngleY - AngleY
		Distance = math.abs(Distance) > 180 and Distance - (Distance / math.abs(Distance)) * 360 or Distance
		AngleY = (AngleY + Distance * 0.35) % 360

		Camera.CameraType = Enum.CameraType.Scriptable

		local Head = Character:FindFirstChild("Head")
		if Head then
			Camera.CFrame = CFrame.new(Head.Position) * CFrame.Angles(0, math.rad(AngleY), 0) * CFrame.Angles(math.rad(AngleX), 0, 0) * HeadOffset
			HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, math.rad(AngleY), 0)
		end

		if (Camera.Focus.Position - Camera.CFrame.Position).Magnitude < 1 then
			Running = false
		else
			Running = true
			UserInputService.MouseBehavior = _G.freemouse and Enum.MouseBehavior.Default or Enum.MouseBehavior.LockCenter
		end

		if not CanToggleMouse.Allowed then
			_G.freemouse = false
		end

		Camera.FieldOfView = FieldOfView

		if Walkspeeds.Enabled then
			if W and S then
				return
			end

			if W and not LeftShift then
				FieldOfView = lerp(FieldOfView, DefFOV, EasingTime)
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.WalkingSpeed, EasingTime)
			elseif W and A or W and D then
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.DiagonalSpeed, EasingTime)
			elseif S then
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.BackwardsSpeed, EasingTime)
			elseif S and A or S and D then
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.BackwardsSpeed - (Walkspeeds.DiagonalSpeed - Walkspeeds.BackwardsSpeed), EasingTime)
			elseif D or A then
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.SidewaysSpeed, EasingTime)
			elseif not LeftShift then
				FieldOfView = lerp(FieldOfView, DefFOV, EasingTime)
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.WalkingSpeed, EasingTime)
			end

			local MoveDirection = Humanoid.MoveDirection
			local LookVector = HumanoidRootPart.CFrame.LookVector.Unit * 100
			local Difference = (MoveDirection - LookVector).Magnitude

			if LastSprint then
				local TimeSince = tick() - LastSprint
				if RunTime >= 2 and TimeSince >= 1 then
					RunTime = OriginalRunTime
				elseif RunTime >= 1 and TimeSince >= 2.5 then
					RunTime = OriginalRunTime
				elseif RunTime > 0 and TimeSince >= 4 then
					RunTime = OriginalRunTime
				end
			end

			if (Difference < 100 and (LeftShift and RunTime > 0)) then
				RunTime -= DeltaTime
				LastSprint = tick()
				if (Player.Dead.Value) then
					RunTime = OriginalRunTime
				end
				FieldOfView = lerp(FieldOfView, Walkspeeds.RunningFOV, EasingTime)
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.RunningSpeed, EasingTime)
			elseif (RunTime <= 0 or Difference >= 100) then
				FieldOfView = lerp(FieldOfView, DefFOV, EasingTime)
				Humanoid.WalkSpeed = lerp(Humanoid.WalkSpeed, Walkspeeds.WalkingSpeed, EasingTime)
				if not IsDebouncing then
					IsDebouncing = true
					task.delay(RunCooldown, function()
						RunTime = OriginalRunTime
						IsDebouncing = false
					end)
				end
			end
		end
	end


	local GameSettings = UserSettings().GameSettings
	
	local function ReverseValue(OriginalValue)
		return 0.1 + 4 - OriginalValue
	end
	
	local function InitiateSettings()
		if UserInputService.MouseEnabled == true then
			local MouseSensitivity = GameSettings.MouseSensitivity
			local GoalSensitivity = OriginalSensitivity * MouseSensitivity
			Sensitivity = GoalSensitivity
		end
		
		if UserInputService.GamepadEnabled == true then
			local GamepadCameraSensitivity = GameSettings.GamepadCameraSensitivity
			local GoalSensitivity = OriginalSensitivity * GamepadCameraSensitivity
			Sensitivity = GoalSensitivity
		end
	end
	
	InitiateSettings()
	
	local function OnGameSettingsChanged(SettingString: string)
		local CanGetSetting, Setting = pcall(function()
			return GameSettings[SettingString]
		end)
		
		if CanGetSetting then
			if SettingString == "MouseSensitivity" then
				local GoalSensitivity = OriginalSensitivity * Setting
				Sensitivity = GoalSensitivity
				--// print("Setting Sensitivity to:", GoalSensitivity) --// For Debugging Purposes
			elseif SettingString == "GamepadCameraSensitivity" then
				local GoalSensitivity = OriginalSensitivity * Setting
				Sensitivity = GoalSensitivity
				print("Setting Sensitivity to:", GoalSensitivity, "from a setting of:", Setting) --// For Debugging Purposes
			end
		end
	end
	
	GameSettings.Changed:Connect(OnGameSettingsChanged)
	
	RunService:BindToRenderStep("CameraSystem", Enum.RenderPriority.Camera.Value, OnRenderStepped)
end

CameraSetup()

The issue you’re probably running into here is that DragDetectors process the input which makes GameProcessed to true. Try removing that guard clause at the beginning of OnInputBegan() and see if that helps while also not bringing too much unintended functions.

1 Like

Ok! I tried outright removing the “GameProcessed” guard clause but that didn’t seem to work. Instead, I just allowed mousemovement to be bypassed and that did the trick flawlessly

InputType.UserInputType ~= Enum.UserInputType.MouseMovement

I’ve been stumped with this one for a while, thank you for your assistance +1

1 Like

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