Image pans slightly with mouse

I’m currently working on a menu and I’d like the background image to slightly pan with the the mouse

(Similar to this, but with UI: Camera Panning Slightly for a menu screen

How would I go about making this?

1 Like

Does anyone know how to do this? I’m currently trying to figure it out and am confused

so ive actually figured this out myself. For anyone in the future who’s wondering, here’s my code:


local image = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local scale = .1 -- the lower, the farther it goes

scale = scale*100
local screenCenter = UDim2.new(0.5,0,0.5,0)

game["Run Service"].RenderStepped:Connect(function()
	
	local screenSize = workspace.CurrentCamera.ViewportSize
	local mousePosition = UDim2.new(mouse.X/screenSize.X,0,mouse.Y/screenSize.Y,0)
	
	local offset = UDim2.new((mousePosition.X.Scale-screenCenter.X.Scale)/scale,0,(mousePosition.Y.Scale-screenCenter.Y.Scale)/scale,0)
	
	image.Position = UDim2.new(0,0,0,0) + offset
end)