Camera manipulation is where you use the player’s camera to create unique effects such as cutscenes, flashbacks and much more. The greatest thing about it though is that it’s easier than it seems.
Getting the camera
There is more than one way to get the camera.
Using a Script
Getting the camera of the players is probably the most complicated part of camera manipulation. To do so, we will have to access the CurrentCamera, which is only available through a
LocalScript|LocalScript. Now the easiest way to get a LocalScript into the player without using a gui is to have a normal script with a LocalScript inside it. Then we will clone the LocalScript out of the normal script and put it into the player’s character. This means the normal script will look something like this:
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) script.LocalScript:clone().Parent = character end) end)
- A LocalScript can also be placed in the
StarterPack|StarterPackinstead of using the code above to insert one during game time.
Now the LocalScript will go into the character each time they respawn. But wait, what if we want it to only go into them the FIRST time the spawn? Well then that will look like this :
game.Players.PlayerAdded:connect(function(player) script.LocalScript:clone().Parent = player.CharacterAdded:wait() end)
Now that the LocalScript is in the player, we need to grab the camera. Well because it’s a LocalScript, we can use CurrentCamera which will give us the players camera by simply doing workspace.CurrentCamera. So to get the camera we will have to put this in the LocalScript :
local cam = workspace.CurrentCamera
and that’s it! Now we can take control of their camera and manipulate it to our will.
Properties of the camera
Now that we have the camera, we have to learn how to use it right? The
Camera|Camera object has four properties we need to worry about : CameraSubject, CameraType, CoordinateFrame and Focus.
The CameraSubject is the brick that the camera will follow. Example :
This will make the camera be attached to Part.
CameraType defines how your camera will be allowed to be manipulated by the player. This is an enum, and you can
Enum/CameraType. Example :
cam.CameraType = "Attach"
This will make the camera attached to the CameraSubject.
CoordinateFrame is the CFrame position of the camera. If you have trouble remembering that it’s CFrame not Vector3, remember that CFrame means CoordinateFrame. Example
This will make the camera go to 10,10,10
Focus sets the position the camera is looking towards. You can also do this with CoordinateFrame by using lookVector however, with Focus if the CameraSubject is defined it will point from the CameraSubject’s position to the CFrame identified. Example :
This will make the camera look at 20,3,2.
Now that you know how to use the camera, it is time to start creating some special effects. I will show some of the most commonly asked for effects, however, feel free to make your own.
Circling the part
This is a fairly simple technique. First, we will make the CameraSubject the part we want to circle. Then we will use a while loop to make it keep going. Next, we will use a variable,
angle, and increment it by 1 degree every iteration. Then we will use some basic CFraming to position the camera. Note: This script needs to be a
LocalScript in order to properly function.
local target = workspace.Part local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target local angle = 0 while wait() do camera.CoordinateFrame = CFrame.new(target.Position) --Start at the position of the part * CFrame.Angles(0, angle, 0) --Rotate by the angle * CFrame.new(0, 0, 5) --Move the camera backwards 5 units angle = angle + math.rad(1) end
Fixing the camera once we’re done.
Camera control to the player, we need to set the
CameraSubject to the character’s
Humanoid, which is the default. This, of course, will have to run in a
LocalScript. The below code will fix it.
game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid game.Workspace.CurrentCamera.CameraType = "Custom"
When players login, circle the entire place with the camera for a few seconds. Bonus points if you make a GUI or title display!
--This must be a LocalScript placed in the StarterGui local target = workspace.BasePlate local camera = workspace.CurrentCamera camera.CameraType = Enum.CameraType.Scriptable camera.CameraSubject = target --camera.Focus = CFrame.new(target.Position) local angle = 0 local i = 0 while wait() do camera.CoordinateFrame = CFrame.new(target.Position) --Start at the position of the part * CFrame.Angles(0, angle, 0) --Rotate by the angle * CFrame.new(0, 200, 500) --Move the camera backwards 5 units --camera.Focus = CFrame.new(target.Position) angle = angle + math.rad(1) i = i + 1 if i > 1000 then break end end