Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Roblox Developer LogoGet StartedLearn RobloxAPI ReferenceCommunity
- Search...
- Camera manipulation
- Contents
- 1 Introduction
- 2 Getting the camera
- 2.1 Using a Script
- 3 Properties of the camera
- 3.1 CameraSubject
- 3.2 CameraType
- 3.3 CoordinateFrame
- 3.4 Focus
- 4 Creating effects
- 4.1 Circling the part
- 5 Fixing the camera once we're done.
- 6 Practice
- 6.1 Exercise
- 7 See Also
- Introduction
- Camera manipulation is where you use the players 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. 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 StarterGui or StarterPack instead 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 object has four properties we need to worry about : CameraSubject, CameraType, CoordinateFrame and Focus.
- CameraSubject
- The CameraSubject is the brick that the camera will follow. Example :
- cam.CameraSubject=workspace.Part
- This will make the camera be attached to Part.
- CameraType
- CameraType defines how your camera will be allowed to be manipulated by the player. This is an enum, and you can see those here. Example :
- cam.CameraType = "Attach"
- This will make the camera attached to the CameraSubject.
- CoordinateFrame
- 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
- cam.CoordinateFrame=CFrame.new(10,10,10)
- This will make the camera go to 10,10,10
- Focus
- 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 :
- cam.Focus=CFrame.new(20,3,2)
- This will make the camera look at 20,3,2.
- Creating effects
- 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.
- To return 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 local script. The below code will fix it.
- game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
- game.Workspace.CurrentCamera.CameraType = "Custom"
- Practice
- Exercise
- Instructions
- When players login, circle the entire place with the camera for a few seconds. Bonus points if you make a GUI or title display!
- Solution
- See Also
- Camera
- LocalScript
- ©2014-2018 Roblox Corporation. All rights reserved.
- Roblox logos, names, and all related indicia are trademarks of Roblox Corporation.
- Company
- About Roblox
- Careers
- Blog
- Terms of Service
- Privacy Policy
- Developers
- Getting Started
- Tutorials
- API Reference
- Community
Advertisement
Add Comment
Please, Sign In to add comment