I’m trying to make a map GUI for my game. I have got the panning to work, but I’m not happy with the zooming. Currently, it zooms toward the anchor point of the MapImage, but I want it to zoom toward the mouse position.
This is the file structure of the map:
This is the code I have so far:
local ZoomDistance = MIN_ZOOM
local Dragging = false
local LastDragPosition = nil
local function updateZoom()
MapImage.Size = UDim2.new(ZoomDistance, 0, ZoomDistance, 0)
end
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Dragging = true
LastDragPosition = input.Position
end
end)
UserInputService.InputChanged:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseWheel then
ZoomDistance = math.clamp(ZoomDistance + input.Position.Z * 0.25, MIN_ZOOM, MAX_ZOOM)
updateZoom()
elseif input.UserInputType == Enum.UserInputType.MouseMovement then
if Dragging then
local delta = input.Position - LastDragPosition
MapImage.Position = MapImage.Position + UDim2.new(0, delta.X, 0, delta.Y)
LastDragPosition = input.Position
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Dragging = false
end
end)
Any help is greatly appreciated!