Making camera move slightly with your mouse?

A main menu shouldn’t be bland. If it’s bland, you’re probably doing something wrong.
Backgrounds on their own are almost always bland – which is main menus never have backgrounds on their own.

The main menu should capture the player’s attention with things like logos, buttons, etc.


Anyway, if you want to look into making camera effects, you’d want to:

  • Detect mouse movement with UserInputService (or ContextActionService)
  • Use the mouse object to update the camera every frame
  • Move camera from the default position based on how far the mouse moves from the center of the screen

Here’s an example of the latter logic:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Camera = game.Workspace.CurrentCamera

local DefaultCFrame = Camera.CFrame
local Scale = 200

function Update()
    -- get the center of the screen
    local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
    -- get the movement (it's in studs, and the mouse properties are in pixels, so you want to divide it by your scale to not move the camera really really far)
    local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, (Mouse.Y-Center.Y)/Scale, 0)
    -- CFrame * CFrame makes it work the same regardless of rotation, where addition just makes it work for one direction
    Camera.CFrame = DefaultCFrame * CFrame.new(DefaultCFrame.p + MoveVector)
end

game:GetService("RunService").RenderStepped:Connect(Update) -- update every frame
83 Likes