I want to make a system where you can zoom in and out into a map with the mouse wheel.
The system I have right now is really buggy and doesn’t work well.
I have searched the Dev Forum and tried to find an answer, but I couldn’t find anything specific.
local Map = script.Parent.Map
-- [VARIABLES] --
local MapPosition = Map.AbsolutePosition
local ZoomMultiplier = 0.25
local MinZoom = 1.75
local MaxZoom = 4
-- [MAIN] --
local function Zoom(Direction)
if Direction == 1 and Map.UIScale.Scale < MaxZoom then
TweenService:Create(Map.UIScale, TweenInfo.new(0.125), {Scale = Map.UIScale.Scale + ZoomMultiplier}):Play()
elseif Direction == -1 and Map.UIScale.Scale >= MinZoom then
TweenService:Create(Map.UIScale, TweenInfo.new(0.125), {Scale = Map.UIScale.Scale - ZoomMultiplier}):Play()
end
TweenService:Create(Map, TweenInfo.new(0.125), {Position = UDim2.new(
Map.Position.X.Scale,
(Mouse.X - MapPosition.X) * ZoomMultiplier,
Map.Position.Y.Scale,
(Mouse.Y - MapPosition.Y) * ZoomMultiplier
)}):Play()
MapPosition = Map.AbsolutePosition
end
The map’s position is {0.5, 0},{0.5, 0} and the anchor point is 0.5, 0.5, also it has an UIAspectRatioConstraint that is 1.
Thank you.