How to switch perspectives from one Camera Object to Another Camera Object?

Hi guys so, I want to try and experiment with something, but this method of mine relies on switching to a different camera object.

Screenshot 2024-08-16 151128

In this screenshot, there are 2 camera objects, the “Camera” being the default camera of the client/player, and the “FPSCam”, where it’s following the player’s head every frame.

I’m using the “Camera” to spectate the player via this line

– SPECTATING the current player
Camera.CameraSubject = player.Character

and while the player is spectating the other player, there’s a feature on top of this I’m working on, where if the “Camera” is near the player (< 5 Studs) then camera perspective will then switch to the “FPSCam” object, and if the camera is far from the player (> 5 studs), it will return it’s perspective back to the “Camera” object.

I’ve been doing some API research with regards to this, but nothing’s popping up, I would like to inquire if this method of camera switching perspective from one camera to another camera object is possible in roblox?

FYI: these 2 camera objects are present on the local end.

Thanks.

CurrentCamera

The Camera object being used by the local player.

How to use CurrentCamera

This property can be set. When it is set, all other Camera objects in the Workspace are destroyed, including the previous CurrentCamera. If this property is set to nil, or the CurrentCamera is otherwise destroyed, a new Camera will be created and assigned. Developers should avoid setting this property to nil or destroying the CurrentCamera however as it can have unintended consequences.

When looking for a client’s Camera object, developers should use this property rather than looking for a child of Workspace named ‘Camera’.

1 Like

You would just make set the CurrentCamera to your FPS cam. CurrentCamera is defined as the camera that the client is currently using/possessing. So changing it would make the local player use the camera you want. Take note that CurrentCamera can only be accessed via a local script. So you would need to place a local script in StarterPlayerScripts for this, since you only want to change the camera when the player joins.

local player = game.Players.LocalPlayer
local FPSCam = workspace.FPSCam

workspace.CurrentCamera = FPSCam
1 Like

Thanks for this, I never knew you could assign it that way. :smiley:

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