pischokiller

Untitled

Apr 7th, 2018
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.28 KB | None | 0 0
  1. Roblox Developer LogoGet StartedLearn RobloxAPI ReferenceCommunity
  2. Search...
  3. Camera manipulation
  4. Contents
  5. 1   Introduction
  6. 2   Getting the camera
  7. 2.1 Using a Script
  8. 3   Properties of the camera
  9. 3.1 CameraSubject
  10. 3.2 CameraType
  11. 3.3 CoordinateFrame
  12. 3.4 Focus
  13. 4   Creating effects
  14. 4.1 Circling the part
  15. 5   Fixing the camera once we're done.
  16. 6   Practice
  17. 6.1 Exercise
  18. 7   See Also
  19. Introduction
  20. 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.
  21.  
  22. Getting the camera
  23. There is more than one way to get the camera.
  24.  
  25. Using a Script
  26. 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 :
  27.  
  28. game.Players.PlayerAdded:connect(function(player)
  29.    player.CharacterAdded:connect(function(character)
  30.        script.LocalScript:clone().Parent = character
  31.    end)
  32. end)
  33. A LocalScript can also be placed in the StarterGui or StarterPack instead of using the code above to insert one during game time.
  34.  
  35. 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 :
  36.  
  37. game.Players.PlayerAdded:connect(function(player)
  38.    script.LocalScript:clone().Parent = player.CharacterAdded:wait()
  39. end)
  40. 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 :
  41.  
  42. local cam = workspace.CurrentCamera
  43. and that's it! Now we can take control of their camera and manipulate it to our will.
  44.  
  45. Properties of the camera
  46. 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.
  47.  
  48. CameraSubject
  49. The CameraSubject is the brick that the camera will follow. Example :
  50.  
  51. cam.CameraSubject=workspace.Part
  52. This will make the camera be attached to Part.
  53.  
  54. CameraType
  55. 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 :
  56.  
  57. cam.CameraType = "Attach"
  58. This will make the camera attached to the CameraSubject.
  59.  
  60. CoordinateFrame
  61. 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
  62.  
  63. cam.CoordinateFrame=CFrame.new(10,10,10)
  64. This will make the camera go to 10,10,10
  65.  
  66. Focus
  67. 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 :
  68.  
  69. cam.Focus=CFrame.new(20,3,2)
  70. This will make the camera look at 20,3,2.
  71.  
  72. Creating effects
  73. 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.
  74.  
  75. Circling the part
  76. 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.
  77.  
  78. local target = workspace.Part
  79. local camera = workspace.CurrentCamera
  80. camera.CameraType = Enum.CameraType.Scriptable
  81. camera.CameraSubject = target
  82. local angle = 0
  83.  
  84. while wait() do
  85.    camera.CoordinateFrame = CFrame.new(target.Position)  --Start at the position of the part
  86.                           * CFrame.Angles(0, angle, 0) --Rotate by the angle
  87.                           * CFrame.new(0, 0, 5)       --Move the camera backwards 5 units
  88.    angle = angle + math.rad(1)
  89. end
  90. Fixing the camera once we're done.
  91. 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.
  92.  
  93. game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
  94. game.Workspace.CurrentCamera.CameraType = "Custom"
  95.  
  96. Practice
  97. Exercise
  98. Instructions
  99.  
  100. When players login, circle the entire place with the camera for a few seconds. Bonus points if you make a GUI or title display!
  101.  
  102. Solution
  103.  
  104.  
  105. See Also
  106. Camera
  107. LocalScript
  108. ©2014-2018 Roblox Corporation. All rights reserved.
  109.  
  110. Roblox logos, names, and all related indicia are trademarks of Roblox Corporation.
  111.  
  112. Company
  113. About Roblox
  114. Careers
  115. Blog
  116. Terms of Service
  117. Privacy Policy
  118. Developers
  119. Getting Started
  120. Tutorials
  121. API Reference
  122. Community
Advertisement
Add Comment
Please, Sign In to add comment