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?
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.
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
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.
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
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.
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