Camera Panning Slightly for a menu screen

Hello there! So my question is regarding a slight camera pan i’m trying to create for a main menu screen, the camera is on scriptable and at the cframe that i want, but i want when you move my mouse either left or right or up and down, it will move slightly in that direction. I’ve searched for this, but not having much luck, the closes one i could find looked like this

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

But i’s not working. Keeps moving my camera elsewhere despite changing the “DefaultCFrame” to what i want. I’ve also experimented with changing the camera focus on mouse move, or renderstepped, or heartbeat, and then using the mouses orign or hit, or target.CFrame, but nothing. Can anyone help?

11 Likes

The script you provided works perfectly fine, I edited it a bit and it got me these results:

https://gyazo.com/c3e243a29fc7441c475f5b3139774a82

The script I used with some edits:

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

Camera.CameraType = "Scriptable"
local DefaultCFrame = workspace.Part.CFrame
local Scale = 500

function Update()
	local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
	local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, -(Mouse.Y-Center.Y)/Scale, 0)
	Camera.CFrame = DefaultCFrame * CFrame.new(DefaultCFrame.p + MoveVector)
end
game:GetService("RunService").RenderStepped:Connect(Update)

Make sure DefaultCFrame is set to the part you want it to be, not just camera as it’s going to set the camera where the character is first spawned in.

8 Likes

I did set the defaultcframe as the cframe i want, the part.Cframe, it keeps showing the camera in the sky somewhere in the middle of nowhwere

1 Like

Did you make sure that the Front Surface is facing the direction of your model?

My code is:

local GypsyCircus = workspace.Spawn_Game:FindFirstChild("Gyspy_Circus")
local GypsyCams = GypsyCircus:FindFirstChild("Cameras")
local Camera = game.Workspace.CurrentCamera
local Mouse = player:GetMouse()
Camera.CameraType = "Scriptable"
local DefaultCFrame = GypsyCams.GypsyCam1.CFrame
local Scale = 500

game:GetService("RunService").RenderStepped:Connect(function()
	if finishedintro == true then
	local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
	local MoveVector = Vector3.new((Mouse.X-Center.X)/Scale, -(Mouse.Y-Center.Y)/Scale, 0)
	Camera.CFrame = DefaultCFrame * CFrame.new(DefaultCFrame.p + MoveVector)
end
end)

yes. Before i just changed the camera cframe to the part i want the usual normal way, and it was fine, did exactly what i needed, but this keep showing me nothing XD

2 Likes

the if finishedintro == true then thing is making it wait till the main intro is finished. Then poof.

1 Like

Did you define finishedintro and if so when did you set it to true? that could be the problem here

I think
Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(DefaultCFrame.p, DefaultCFrame.p + MoveVector), 0.5)
is what you’re looking for

not sure, could be wrong.

2 Likes

I tested the code they provided and it worked flawlessly, I believe they arent setting “finishedintro” to true after the intro is played.

1 Like

Oh alright, well hopefully their problem has been solved, originally I thought he would’ve liked to have the LookDirection move instead of the position, because I think that’s how it’s done in other games.

1 Like

I just tried it with a random part named “Part” in the workspace, and it worked, but when i try to index the exact part i want that sits in the folder… it doesnt work, i even moved it into the workspace, and still, its not working. It’s strange

1 Like

There are no errors? Perhaps the part is not anchored? CanCollide and anchored is off? You mispelled the name? That’s all I can think of.

Checked all of that. :confused: Its all fine. Hmph

1 Like

I guess you solved it yourself, perhaps just use that part, rename it, etc. Best of luck to ya!

1 Like

I moved it and changed the name… still didnt work :confused: ughh. i think it has to do with maybe where it is? idk

Can you provide screenshot of where that part is? or its properties? I can’t think of any other problems this might have, considering several solutions posted by other members.

1 Like

And again it works fine when just doing a basic game.Workspace.CurrentCamera.CFrame = GypsyCameras.GypsyCam1.CFrame. But i’m determined to get the camera pan working, just to add a layer of depth in

just for the sake of showing you, this is what happens as i set it normally

then upon activating the rendered step function, and its suppose to be taking me to the same place… this is what happens:

Is it local script or server script?