Need help with a custom camera script

(ps: this is my first post and I don’t know if i’m setting this up right, also my grammar is not too good)

  1. What do you want to achieve? Keep it simple and clear!

I want to move the camera’s position to another location. I’m making a FNAF game and am trying to make a camera system.

  1. What is the issue? Include screenshots / videos if possible!

My only idea is too move the part where the camera positions it too another place when pressing space. The part moves but the camera stays in place. The camera script was copied from a tutorial as I do not know how to move or manipulate the players camera due to my limited knowledge. (its the only thing I copied though.)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

as I stated before, My only idea is too move the part where the camera positions it too another place when pressing space. Its hard to use the dev forum due to my siltation. I could always wait for the second part releases so I can make it work. Though its been 2 months already and I’m not that patient.

Screenshot_170
^ where the module script is located (the blue one)

code (the camera itself works incredibly well its just moving it doesn’t work)

local RS = game:GetService("RunService")
local PS = game:GetService("Players")

-- | Variables | --
local player = PS.LocalPlayer
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera

local WorkplaceUtilities = workspace:WaitForChild("WorkplaceUtilities")
local CameraPart = WorkplaceUtilities:WaitForChild("CameraPart")

local pivotPoint = CameraPart.CFrame

-- | Constant | --
local CAMERA_RENDER_KEY = "Render Camera"

local CameraController = {}

function CameraController:Enable()
	local function RenderCamera()
		cam.CameraType = Enum.CameraType.Scriptable
		cam.CameraSubject = nil
		cam.FieldOfView = 70 -- | You can adjust
		
		local centerPos, mousePos = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2), Vector2.new(mouse.X, mouse.Y)
		local xDist, yDist =  mousePos.X - centerPos.X, mousePos.Y - centerPos.Y
		
		local xRot, yRot = math.rad(yDist), math.rad(xDist)
		xRot, yRot = xRot/(cam.ViewportSize.X * 0.01), yRot/(cam.ViewportSize.Y * 0.01)
		xRot, yRot = math.clamp(xRot, math.rad(-75), math.rad(75)), math.clamp(yRot, math.rad(-65), math.rad(65))
		
		xRot, yRot = -xRot, -yRot
		
		cam.CFrame = pivotPoint * CFrame.Angles(xRot, yRot, 0)
	end
	RS:BindToRenderStep(CAMERA_RENDER_KEY, Enum.RenderPriority.Camera.Value, RenderCamera)
end

return CameraController
1 Like

this was resolved so dont bother replying
i cant figure out how to delete the post so ya

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.