Camera Manipulation

Have you ever seen a game where they change the player’s camera? Such as Kitchen Gun by @Inkthirsty. In this tutorial I’ll explain how you can change the player’s camera view.

To start off, put a local script in StarterPack:
Screen Shot 2020-11-14 at 8.10.47 PM

Now let’s hop into the script, let’s define the CurrentCamera and the custom camera you want the player to have. If you want, it might also be helpful to define the player. Like this:

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local CurrentCamera = game.Workspace.CurrentCamera
local NewCam = game.Workspace.NewCam

We’ll end up messing with the current camera later in the script, but first let’s make sure the camera can be changed. Make a function named, changeMode() and put this inside:


function changeMode()
	repeat wait()
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		
		
	until CurrentCamera.CameraType == Enum.CameraType.Scriptable
	
	
end

This will allow us to change the camera, and it will be helpful later. Now that we finished that, everything else is extremely easy.

Below the changemode() function, make a function named changecamera(). This is the function we will use to change the player’s camera. In the function put:

function changeCamera()
	CurrentCamera.CFrame = NewCam.CFrame
	
	
	wait()
end

That will change the camera’s CFrame, to change the camera into the part that you wanted it to change to.

If you go ahead and run it, you can see that nothing happens, that’s because you never triggered the functions. At the very bottom of the script, put:

changeMode()
changeCamera()

In the end we should have this script:

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAdded:Wait()

local CurrentCamera = game.Workspace.CurrentCamera
local NewCam = game.Workspace.NewCam

function changeMode()
	repeat wait()
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
		
		
	until CurrentCamera.CameraType == Enum.CameraType.Scriptable
	
	
end


function changeCamera()
	CurrentCamera.CFrame = NewCam.CFrame
	
	
	wait()
end

changeMode()
changeCamera()

If you go ahead and run it your camera will change to the new camera! You can use this for numerous amount of projects you might want to develop.

I hope this helps you in the future, and thank you for taking your time to read this. Have a good day!

13 Likes

There is a lot of unnecessary polling and waits, what are the reasons for this? When I’m dealing with camera, I’ve never had to poll to change camera state once nor did I need waits.

4 Likes

A script like this doesn’t need multiple functions. Just do this:

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = workspace.CameraPart.CFrame

and it would work like a charm.

14 Likes

This doesn’t give any tutorials on Camera Manipulation. It’s just all about setting the CameraType and setting it to a new CFrame.

3 Likes

You can search up on YouTube or even on the Dev forum, about how to manipulate the camera. Once you know the basics it is really just messing around with it and to see what it looks like and changing it to how you like it. But that script above, is just how to set it up for it to work.

1 Like

Just so you know, you don’t need to make a billion repeat wait() until functions as that could cause lag. You could easily just do something like workspace.CurrentCamera.CFrame = workspace.Part.CFrame
and for changing the cams you should do
changeCamera(workspace.Part)

then

function changeCamera(part) workspace.CurrentCamera.CFrame = part.CFrame end

4 Likes