Draggable scrollingframe is acting all screwy

https://gyazo.com/5d6ebac64e63abb0ba550ded9478bf17

Ignore this and read my reply instead
I reckon the problem is the fact that old_mouse_pos is only being updated on InputBegan, so as long as the mouse is above where the player first clicked, regardless of what direction the mouse is moving afterward, it will keep moving in that one direction as long as it’s above or below where the player first clicked to drag.

local function InputBegan(input, process)
	if input.UserInputType  == Enum.UserInputType.MouseButton1 then
		move_map = true
		old_mouse_pos = UIS:GetMouseLocation()
	end
end

local function InputChanged(input, process)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		if not move_map then return end
		local mouse_location = UIS:GetMouseLocation()
		local Direction = (Vector2.new(-(mouse_location.X - old_mouse_pos.X), -(mouse_location.Y - old_mouse_pos.Y)) - map.AbsolutePosition) / dampener
		map.CanvasPosition = Vector2.new(map.CanvasPosition.X + Direction.X, map.CanvasPosition.Y + Direction.Y)
	end
end

local function InputEnded(input, process)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		move_map = false
	end
end

you can use mouse.Move event that triggers everytime mouse position changes, from there check if frame is visible n do the stuff, example:

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Move:Connect(function() 
    if frame.Visible and movemap then
      --  do stuff yere
    end
end)
1 Like

Added this to the script to update old_mouse_pos whenever it finds the player hasn’t moved their mouse. It doesn’t work either so I don’t think that’s the problem.

RunService.Heartbeat:Connect(function()
	if old_mouse_pos == UIS:GetMouseLocation() then
		old_mouse_pos = UIS:GetMouseLocation()
	end
end)

I’m guessing it might have something to do with the way I’m calculating the scrolling frame movement like I’m actually adding onto the position every time the mouse moves when it should be directly “replicating” the mouse location to the canvas position

		local Direction = (Vector2.new(-(mouse_location.X - old_mouse_pos.X), -(mouse_location.Y - old_mouse_pos.Y)) - map.AbsolutePosition) / dampener
		map.CanvasPosition = Vector2.new(map.CanvasPosition.X + Direction.X, map.CanvasPosition.Y + Direction.Y)
1 Like