How would i make my camera follow my cursor slightly

where would i put the script and set the c frame to the part?

Hey, I tested my code in Studio and of course it doesn’t work. I’m currently rewriting it, sorry!

1 Like

oh its fine im just fixing animations with the little noob!

Here is another way to do it without needing a mouse target or hit. This is useful for if you have target filters or have your mouse pointing at the sky, as mouse.Hit might return a crazy number or just plain old nil.

You can use the ViewSize of mouse to get the Vector2 position on your screen (basically UDim2.fromOffset) that your mouse is in.

Anyway, here is the code of how you would implement it:

--// Variables
local camPart = workspace["Camera Part Goes Here"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

--// Set cam
repeat
      wait()
      cam.CameraType = Enum.CameraType.Scriptable
until
      cam.CameraType == Enum.CameraType.Scriptable

--// Move cam
local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
      cam.CFrame = camPart.CFrame * CFrame.Angles(
            math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
            math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
            0
      )
end)
11 Likes

so id just put it in here correct?

1 Like

You could put it there, but I normally put my camera scripts in StarterGui.

LocalScripts run in StarterPlayerScripts (Player), StarterCharacterScripts (Character), StarterGui (PlayerGui), and tools (Backpack/Character)

3 Likes

yeah i just thought it would run better for 1 player all together then just it being server wide

It is still for one player either way.

2 Likes

14:15:35.932 Camera Part Goes Here is not a valid member of Workspace “Workspace” - Client - Camera:2

1 Like

You’re suppose to replace it with the object you want (Camera Part)

2 Likes

so i would just rename cam to the part i need it to?

The error says Camera Part Goes Here is not a valid member of Workspace meaning that, well… “Camera Part Goes Here” does not exist in the workspace. The part where it says Camera:2 means that it is from the script called “Camera” and on the second line, meaning that it is from the part saying local camPart = workspace[“Camera Part Goes Here”]

In my code, I put that there so you can put your own camera part there. You can do that by adding a new part to the workspace and positioning it where you want the camera to be.

If that seems too difficult or long, I made a plugin specifically for this: Camera Part Maker

The final step is changing the second line to local camPart = workspace.CamPart or replace CamPart with whatever you called the part. (The plugin defaults to CamPart)

3 Likes

im afraid i dont understand the problem still i just lost my script and previous camera part and the script is still giving me the same error

--// Variables
local camPart = workspace["Camera Part Goes Here"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

--// Set cam
repeat
      wait()
      cam.CameraType = Enum.CameraType.Scriptable
until
      cam.CameraType == Enum.CameraType.Scriptable

--// Move cam
local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
      cam.CFrame = camPart.CFrame * CFrame.Angles(
            math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
            math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
            0
      )
end)

The part where it says Camera Part Goes Here needs to be renamed to the name of your camera part

4 Likes

and what about the parts that say cam?

--// Variables
local cam = workspace.CurrentCamera
local camPart = workspace["CameraPart"]
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

--// Set cam
repeat
      wait()
      cam.CameraType = Enum.CameraType.Scriptable
until
      cam.CameraType == Enum.CameraType.Scriptable

--// Move cam
local maxTilt = 10
game:GetService("RunService").RenderStepped:Connect(function()
      cam.CFrame = camPart.CFrame * CFrame.Angles(
            math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
            math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
            0
      )
end)
62 Likes

thanks for the help i appreciate it alot it looks really nice now

7 Likes

Wonderful! I hope your game goes well. I’d appreciate it if you would mark a solution by choosing the tick box next to the heart icon!

9 Likes

yup! ive already done it and thanks its gonna be pretty cool

3 Likes

Sorry for trying to revive an old post! but how would it be if it was converted to mouse delta?

3 Likes