How would i make a custom camera script that can rotate 90 degrees up and vice versa?

Hello! this is my first post on the DevForum!

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a custom camera script that can follow the player, and also be able to zoom in and rotate 90 degrees up, and -90 degrees down.

I know how to script, but i’m not really sure about how i could make a custom camera. I do know i could use CFrames and CameraSubject though.
I’m trying to make an FPS game, and i need to make a camera that can rotate -90 down and 90 degrees up.
Help appreciated! :grin:

Change the CameraType to Scriptable in your custom camera script.

This should be a modular script to allow you to toggle this functionality, because you can’t just set the CameraType to Scriptable to stop your own script, like you could previously.

That’s not possible with ROBLOX’s current camera. But you can “fake it” by changing the ViewSize of the camera and moving it behind the player.
local player = game.Players.LocalPlayer
local humanoid = player.Character:FindFirstChild(“Humanoid”)
local cam = workspace.CurrentCamera

cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.new(0,0,0) * CFrame.Angles(0,0,0)
cam.FieldOfView = 1

local function updateCam(pos,rot)
cam.CFrame = CFrame.new(pos.x, pos.y, pos.z) * CFrame.Angles(0,r

I have made a very simple camera script, using the code below:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera

local x_rotation_clamp = math.pi/2 - 0.01

local UIS = game:GetService(“UserInputService”)

local playerGui = player.PlayerGui
local folder = Instance.new(“Folder”)
folder.Name = “CameraGui”
folder.Parent = playerGui

local screenGui = Instance.new(“ScreenGui”)
screenGui.Name = “CameraGui”
screenGui.Parent = folder

local mouseFrame = Instance.new(“Frame”)
mouseFrame.Position = UDim2.new(0, 0, 0.5, 0)
mouseFrame.Size = UDim2.new(0, 0, 0, 0)
mouseFrame.Parent = screenGui

mouse.Icon = “”
mouse.KeyDown:connect(function(key)
if key == “v” then
if mouseFrame.Visible then
mouseFrame.Visible = false
else
mouseFrame.Visible = true
end
end
end)

local move_speed = 50

local y_rotation = 0
local y_rotation_change = 0
local x_rotation = 0
local x_rotation_change = 0

camera.CameraType = Enum.CameraType.Custom
camera.CFrame = CFrame.new(0, 0, 0)

local body_cframe = camera.CFrame
local body_cframe_change = CFrame.new(0, 0, 0)

UIS.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
mouseFrame.Position = UDim2.new(0, input.Position.X, 0, input.Position.Y)
end
end)

UIS.InputChanged:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
y_rotation_change = input.Delta.y/100
x_rotation_change = input.Delta.x/100
end
end)

UIS.InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
y_rotation_change = 0
x_rotation_change = 0
end
end)

local move_vector = Vector3.new(0, 0, 0)
local move_vector_change = Vector3.new(0, 0, 0)

UIS.InputBegan:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
move_vector_change = Vector3.new(0, 0, -1)
elseif input.KeyCode == Enum.KeyCode.S then
move_vector_change = Vector3.new(0, 0, 1)
elseif input.KeyCode == Enum.KeyCode.A then
move_vector_change = Vector3.new(-1, 0, 0)
elseif input.KeyCode == Enum.KeyCode.D then
move_vector_change = Vector3.new(1, 0, 0)
end
end
end)

UIS.InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.W then
move_vector_change = move_vector_change - Vector3.new(0, 0, -1)
elseif input.KeyCode == Enum.KeyCode.S then
move_vector_change = move_vector_change - Vector3.new(0, 0, 1)
elseif input.KeyCode == Enum.KeyCode.A then
move_vector_change = move_vector_change - Vector3.new(-1, 0, 0)
elseif input.KeyCode == Enum.KeyCode.D then
move_vector_change = move_vector_change - Vector3.new(1

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