How do I move a camera using a mouse?

Hey, I’m trying to make a game and whenever the game loads you start off at the main menu with a camera stuck onto an area, but if I move my mouse I want the camera to move, how do I do this?

1 Like

I really don’t get what you meant by this.

1 Like

I already found out how to do it, thanks though!

local pt = game.Workspace.camera
local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()

while true do
if Mouse.Move then
pt.CFrame = CFrame.new(pt.Position, Vector3.new(Mouse.Hit.p.x, Mouse.Hit.p.y))
end
game["Run Service"].Heartbeat:Wait()
end
1 Like

Make sure to mark your post as solution.

Personally, I’d do it this method for efficiency and smooth purposes.

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local camPart = nil -- Your cam part

local rotateAmount = 5

local function enable()    
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = camPart.CFrame
    game:GetService("RunService"):BindToRenderStep("CameraLookAtMouse", Enum.RenderPriority.Camera.Value + 1, function()
        camera.CFrame = camPart.CFrame * CFrame.Angles(
            math.rad((mouse.Y - mouse.ViewSizeY) / mouse.ViewSizeY * -rotateAmount),
            math.rad((mouse.X - mouse.ViewSizeX) / mouse.ViewSizeX * -rotateAmount),
            math.rad(0)
        )
    end)
end

local function disable()
    game:GetService("RunService"):UnbindFromRenderStep("CameraLookAtMouse")
    camera.CameraType = Enum.CameraType.Custom
end

enable()

1 Like

The disable function i’m trying to use isnt working though.

Are you calling the function? And is there any errors?

I am calling the function. There are no errors?

LocalScript in StarterPlayerScripts works fine for me.