Can somebody help me with this main menu camera effect or explain this code to me?

Hello, so I was given this code in another post it works but not fully and I want to know why.

local deadZoneDistance = 34 --Will decide how far the camera moves when moving the mouse. The higher the number the less it will move.
local sensitivity = 69 --Will also decide how far the camera moves when moving the mouse. The higher the number the more it will move.
local mousePosX = userInputService:GetMouseLocation().X --mouseX
local mousePosY =  userInputService:GetMouseLocation().Y--mouseY

local MIN_DIST_X = deadZoneDistance
local MIN_DIST_Y = deadZoneDistance
local MAX_DIST_X = workspace.CurrentCamera.ViewportSize.X - deadZoneDistance --Gets the center X of viewport
local MAX_DIST_Y = workspace.CurrentCamera.ViewportSize.Y - deadZoneDistance --Gets the center Y of viewport
			
local regX = sensitivity / ((mousePosX > MAX_DIST_X and MAX_DIST_X) or (mousePosX < MIN_DIST_X and MIN_DIST_X) or mousePosX)
local regY = sensitivity /((mousePosY > MAX_DIST_Y and MAX_DIST_Y) or (mousePosY < MIN_DIST_Y and MIN_DIST_Y) or mousePosY)

local mousePos = Vector3.new(regX, regY, 0)
local result = {CFrame = CFrame.new(cameraPart.Position, mousePos)}
local t1 = tweenService:Create(cameraPart, TweenInfo.new(1), result)
t1:Play()

I fixed some of it up and the comments are mine I don’t know if they explain it right I just want to know what the regX and regY are doing exactly. And what the code is doing is making it so when the player’s mouse is moved to the side of the screen the camera will slightly look that way but it only works right now if the player’s mouse moves to the left side or the upper side of the screen.

Mouse position, you could try setting it to a negative value to get the other two directions done.
Not sure if it’ll work because the last time I tried anything with the camera I failed miserably.

1 Like

I tried this but it did some other weird stuff.

Set some other values like ‘MIN_DIST’ to a negative number.

Experiment with the code, change things around, and make sure you have a backup of it incase you need the original code for later.

Yeah I’ve been trying at this I’m gonna keep trying at it. Im a moderate scripter so I understand the code to an extent.

Well I found out sensitivity when set to negative will move my camera right and down but it will move it right and down still when I move my mouse left and up so I gotta do a little more digging.

local deadZoneDistance = 200
local sensitivity = 200
local mousePosX = userInputService:GetMouseLocation().X --mouseX
local mousePosY =  userInputService:GetMouseLocation().Y--mouseY

local MIN_DIST_X = deadZoneDistance
local MIN_DIST_Y = deadZoneDistance
local MAX_DIST_X = workspace.CurrentCamera.ViewportSize.X - deadZoneDistance
local MAX_DIST_Y = workspace.CurrentCamera.ViewportSize.Y - deadZoneDistance
			
local regX1 = sensitivity / ((mousePosX > MAX_DIST_X and MAX_DIST_X) or (mousePosX < MIN_DIST_X and MIN_DIST_X) or mousePosX)
local regY1 = sensitivity /((mousePosY > MAX_DIST_Y and MAX_DIST_Y) or (mousePosY < MIN_DIST_Y and MIN_DIST_Y) or mousePosY)
			
local regX2 = -sensitivity / ((mousePosX < MAX_DIST_X and MAX_DIST_X) or (mousePosX > MIN_DIST_X and MIN_DIST_X) or mousePosX)
local regY2 = -sensitivity /((mousePosY < MAX_DIST_Y and MAX_DIST_Y) or (mousePosY > MIN_DIST_Y and MIN_DIST_Y) or mousePosY)
			
local regX = regX1 + regX2
local regY = regY1 + regY2

local mousePos = Vector3.new(regX, regY, 0)
local result = {CFrame = CFrame.new(cameraPart.Position, mousePos)}
local t1 = tweenService:Create(cameraPart, TweenInfo.new(1), result)
t1:Play()

with help from @mnmzc and @aaltUser

Glad you were able to solve it. Sorry that I seemed to dip mid thread, I was moving into a new house.

Oh no problem at all the game is looking is nice thanks for your help!

No problem! Good luck with the game!