How can I make the background move with mouse?

Hi, I’m working on an interface and I’m wondering how I can make a UI background move slightly as the mouse moves around the screen.


Mouse moves up
Background moves up by much less

It would also be great if there were mins and maxes like if the background reached out of the screens view.

Have u ever considered skipping all this atan2 crap and just making the x and y range 1 by dividing it by the resolution then using that as the basis of the cameras rotation? Say you linear interpolate the rotational component with 180/pi * 15 + (180/pi * -15 - 180/pi * 15) * t

Where as t is that value we got from 0 to 1.

what has the camera got to do with ui backgrounds i think youre on the wrong thread my friend

Show me a picture of what you want then, my friend

quickly searched it up and here this seems about right

skip to 30s

You could probably apply a matrix transformation on them dependent on what I said, where the middle of the screen is the origin

im not a mad scientist scripter lmao i have no clue what you mean

i think you misunderstand aha

i dont really need the logic side of things, just how in lua roblox would i do this?

No you do need the logic cause if you knew the logic you’d be able to code it.

Math is universal

1 Like

The math isn’t super complicated but what CoderHusk is getting at is you are just taking a value and scaling it. Just note that the GuiElement needs to have its Anchor Point set to 0.5,0.5 for this to work correctly.

local function parallaxEffect(EffectIntensity)
	local Player = game.Players.LocalPlayer
	local Mouse = Player:GetMouse()
	local percentX, percentY = ((Mouse.X / Mouse.ViewSizeX)-0.5)*EffectIntensity+0.5, ((Mouse.Y / Mouse.ViewSizeY)-0.5)*EffectIntensity+0.5
	return percentX, percentY
1 Like