Minimap system originally made for square maps

I took the minimap system from this Roblox Tech Demo game however it was made for square maps. I was wondering how I could get it to work for my rectangular map.

My map is 5638 x 8658 studs and the center point is 576, 1903


local _mapView = {
    focus_x = 0,
    focus_y = 0,
    scale = _minimapZoom
}

local _mapSize = 12000 -- map is 12k x 12k studs
local _minimapWidth = 0.3
local _minimapHeight = 0.3
local _worldmapWidth = 0.9
local _worldmapHeight = 0.9
local _isCurrentlyMinimap = true

local function _updateMapFocus()
    if _isCurrentlyMinimap then
        local character = Util.getClientFocus()

        if not character or not character.PrimaryPart then
            return
        end

        local root = character.PrimaryPart
        local pos = root.Position

        -- Update focus point
        _mapView.focus_x = pos.X + _mapSize / 2 -- the center of our map is at 0,0, so need to offset player position to be in [0, mapsize] range
        _mapView.focus_y = pos.Z + _mapSize / 2 -- the center of our map is at 0,0, so need to offset player position to be in [0, mapsize] range
    else
        -- Set focus point to middle of map for worldmap view
        _mapView.focus_x = _mapSize / 2
        _mapView.focus_y = _mapSize / 2
    end

    -- Panning/scaling of viewport/map
    -- Note:  We use Offsets here to maintain the correct aspect ratio for the map inside the map frame (which may be arbitrarily sized)
    -- TODO:  Currently this assumes a square map
    _map.Size = UDim2.new(0, _mapFrame.AbsoluteSize.X * _mapView.scale,
                          0, _mapFrame.AbsoluteSize.X * _mapView.scale)

    -- Get the viewport position of the map focus point and adjust the map position accordingly.
    local relativeFocus = Vector2.new(_mapView.focus_x / _mapSize,
                                      _mapView.focus_y / _mapSize)

    _map.Position = UDim2.new(0, _mapFrame.AbsoluteSize.X * 0.5 - _map.Size.X.Offset * relativeFocus.X,
                              0, _mapFrame.AbsoluteSize.Y * 0.5 - _map.Size.Y.Offset * relativeFocus.Y)
end
1 Like
local _mapView = {
    focus_x = 0,
    focus_y = 0,
    scale = _minimapZoom
}

local _mapSize = 12000 -- map is 10k x 12k studs
local _mapSize2 = 10000
local _minimapWidth = 0.3
local _minimapHeight = 0.3
local _worldmapWidth = 0.9
local _worldmapHeight = 0.9
local _isCurrentlyMinimap = true

local function _updateMapFocus()
    if _isCurrentlyMinimap then
        local character = Util.getClientFocus()

        if not character or not character.PrimaryPart then
            return
        end

        local root = character.PrimaryPart
        local pos = root.Position

        -- Update focus point
        _mapView.focus_x = pos.X + _mapSize / 2 -- the center of our map is at 0,0, so need to offset player position to be in [0, mapsize] range
        _mapView.focus_y = pos.Z + _mapSize2 / 2 -- the center of our map is at 0,0, so need to offset player position to be in [0, mapsize2] range
    else
        -- Set focus point to middle of map for worldmap view
        _mapView.focus_x = _mapSize / 2
        _mapView.focus_y = _mapSize2 / 2
    end

    -- Panning/scaling of viewport/map
    -- Note:  We use Offsets here to maintain the correct aspect ratio for the map inside the map frame (which may be arbitrarily sized)
    -- TODO:  Currently this assumes a square map
    _map.Size = UDim2.new(0, _mapFrame.AbsoluteSize.X * _mapView.scale,
                          0, _mapFrame.AbsoluteSize.X * _mapView.scale)

    -- Get the viewport position of the map focus point and adjust the map position accordingly.
    local relativeFocus = Vector2.new(_mapView.focus_x / _mapSize,
                                      _mapView.focus_y / _mapSize2)

    _map.Position = UDim2.new(0, _mapFrame.AbsoluteSize.X * 0.5 - _map.Size.X.Offset * relativeFocus.X,
                              0, _mapFrame.AbsoluteSize.Y * 0.5 - _map.Size.Y.Offset * relativeFocus.Y)
end

I have absolutely no idea if this would work, I just split the mapsize variable into 2 variables (1 for the Y and 1 for the X) while the original script used 1 variable for both the Y and X

If it doesn’t work, try reversing the numbers of _mapSize and _mapSize2 (because I wasn’t sure which one would be correct for the height and which for the width) I THINK mapSize2 should be for the Y axis