function ControlModule.SelectTouchModule(q)if not UserInputService.TouchEnabled then return nil,false end local y=nil local K=Players.LocalPlayer.DevTouchMovementMode if K==Enum.DevTouchMovementMode.UserChoice then y=movementEnumToModuleMap[UserGameSettings.TouchMovementMode]elseif K==Enum.DevTouchMovementMode.Scriptable then return nil,true else y=movementEnumToModuleMap[K]end return y,true end function ControlModule.OnRenderStepped(y,q)if y.activeController and(y.activeController.enabled and y.humanoid)then local q=y.activeController:GetMoveVector()local K=false if y.vehicleController then q,K=y.vehicleController:Update(q,y.activeControlModule==Gamepad)end y.moveFunction(Players.LocalPlayer,q,y.cameraRelative)y.humanoid.Jump=y.activeController:GetIsJumping()or y.touchJumpController and y.touchJumpController:GetIsJumping()end end function ControlModule.OnHumanoidSeated(K,q,y)if q then if y and y:IsA("\086\101\104\105\099\108\101\083\101\097\116")then if not K.vehicleController then K.vehicleController=K.vehicleController.new(CONTROL_ACTION_PRIORITY)end K.vehicleController:Enable(true,y)end else if K.vehicleController then K.vehicleController:Enable(false,y)end end end function ControlModule.OnCharacterAdded(y,q)y.humanoid=q:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")while not y.humanoid do q.ChildAdded:wait()y.humanoid=q:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")end if y.humanoidSeatedConn then y.humanoidSeatedConn:Disconnect()y.humanoidSeatedConn=nil end y.humanoidSeatedConn=y.humanoid.Seated:Connect(function(q,K)y:OnHumanoidSeated(q,K)end)end function ControlModule.OnCharacterRemoving(y,q)y.humanoid=nil end

function ControlModule:SelectTouchModule()
	if not UserInputService.TouchEnabled then
		return nil, false
	end
	local touchModule = nil
	local DevMovementMode = Players.LocalPlayer.DevTouchMovementMode
	if DevMovementMode == Enum.DevTouchMovementMode.UserChoice then
		touchModule = movementEnumToModuleMap[UserGameSettings.TouchMovementMode]
	elseif DevMovementMode == Enum.DevTouchMovementMode.Scriptable then
		return nil, true	
	else
		touchModule = movementEnumToModuleMap[DevMovementMode]
	end
	return touchModule, true
end

function ControlModule:OnRenderStepped(dt)
	if self.activeController and self.activeController.enabled and self.humanoid then
		local moveVector = self.activeController:GetMoveVector()

		local vehicleConsumedInput = false
		if self.vehicleController then
			moveVector, vehicleConsumedInput = self.vehicleController:Update(moveVector, self.activeControlModule==Gamepad)
		end

		-- User of vehicleConsumedInput is commented out to preserve legacy behavior, in case some game relies on Humanoid.MoveDirection still being set while in a VehicleSeat
		--if not vehicleConsumedInput then
			self.moveFunction(Players.LocalPlayer, moveVector, self.cameraRelative)
		--end

		self.humanoid.Jump = self.activeController:GetIsJumping() or (self.touchJumpController and self.touchJumpController:GetIsJumping())
	end
end

function ControlModule:OnHumanoidSeated(active, currentSeatPart)
	if active then
		if currentSeatPart and currentSeatPart:IsA("VehicleSeat") then
			if not self.vehicleController then
				self.vehicleController = self.vehicleController.new(CONTROL_ACTION_PRIORITY)
			end
			self.vehicleController:Enable(true, currentSeatPart)
		end
	else
		if self.vehicleController then
			self.vehicleController:Enable(false, currentSeatPart)
		end
	end
end

function ControlModule:OnCharacterAdded(char)
	self.humanoid = char:FindFirstChildOfClass("Humanoid")
	while not self.humanoid do
		char.ChildAdded:wait()
		self.humanoid = char:FindFirstChildOfClass("Humanoid")
	end

	if self.humanoidSeatedConn then
		self.humanoidSeatedConn:Disconnect()
		self.humanoidSeatedConn = nil
	end
	self.humanoidSeatedConn = self.humanoid.Seated:Connect(function(active, currentSeatPart) self:OnHumanoidSeated(active, currentSeatPart) end)
end

function ControlModule:OnCharacterRemoving(char)
	self.humanoid = nil
end
