Advertisement
fatboychummy

AssortedCode

Jul 15th, 2020
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. -- assorted code from two files
  2.  
  3. -- ####################################################################################################################################
  4. -- Relevant bits of the module:
  5. local function defaultRenderStep()
  6.     print("Default Render Step")
  7.     UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
  8.     -- set visibility for parts
  9.     for pPart, nValue in pairs(tPartVisibility) do
  10.         pPart.LocalTransparencyModifier = nValue
  11.     end
  12.    
  13.     -- make the character's body move with the camera, and clamp up/down look.
  14.     local firstPart = Camera
  15.     local secondPart = rootPart
  16.     local firstPartCF = firstPart.CFrame --The first part's CFrame
  17.     local firstPartAngleCF = firstPartCF-firstPartCF.p --The first part's CFrame without the position (Or a position of {0,0,0})
  18.     local x, y, z = firstPartAngleCF:ToEulerAnglesYXZ()
  19.     firstPartAngleCF = CFrame.Angles(0, y, 0)
  20.     secondPart.CFrame = firstPartAngleCF + secondPart.CFrame.p --We set the CFrame to the angle of the first part and the position of the second.
  21.    
  22.     local rX, rY, rZ = Camera.CFrame:ToOrientation()
  23.     local limX = math.clamp(math.deg(rX), -45, 70)
  24.     Camera.CFrame = CFrame.new(Camera.CFrame.p) * CFrame.fromOrientation(math.rad(limX), rY, rZ)
  25. end
  26.  
  27. local function deathRenderStep()
  28.     print("Death Render Step")
  29.     UIS.MouseBehavior = Enum.MouseBehavior.Default
  30.     -- set visibility for parts
  31.     for pPart, nValue in pairs(tPartVisibility) do
  32.         pPart.LocalTransparencyModifier = nValue
  33.     end
  34.    
  35.     -- make the character's body move with the camera, and clamp up/down look.
  36.     local firstPart = rootPart.Parent.Head
  37.     local secondPart = Camera
  38.     local firstPartCF = firstPart.CFrame --The first part's CFrame
  39.     local firstPartAngleCF = firstPartCF-firstPartCF.p --The first part's CFrame without the position (Or a position of {0,0,0})
  40.     local x, y, z = firstPartAngleCF:ToEulerAnglesYXZ()
  41.     firstPartAngleCF = CFrame.Angles(0, y, 0)
  42.     secondPart.CFrame = firstPartAngleCF + secondPart.CFrame.p --We set the CFrame to the angle of the first part and the position of the second.
  43. end
  44.  
  45. function module.DeathCamera()
  46.     print("DEATH CAMERA CALLED!")
  47.     Camera.CameraType = Enum.CameraType.Fixed
  48.     Player.CameraMode = Enum.CameraMode.LockFirstPerson
  49.     Camera.CameraSubject = Player.Character.Head
  50.     RunService:UnbindFromRenderStep("CustomCameraControl")
  51.     RunService:UnbindFromRenderStep("DefaultCameraControl")
  52.     RunService:UnbindFromRenderStep("DeathCameraControl")
  53.     RunService:BindToRenderStep("DeathCameraControl", Enum.RenderPriority.Camera.Value - 5, deathRenderStep)
  54.     print("DEATH CAMERA DONE!")
  55. end
  56.  
  57. -- reset the camera to the default camera.
  58. function module.DefaultCamera()
  59.     print("DEFAULT CAMERA CALLED!")
  60.     Camera.CameraType = Enum.CameraType.Attach
  61.     Player.CameraMode = Enum.CameraMode.LockFirstPerson
  62.     Camera.CameraSubject = Player.Character.Head
  63.     RunService:UnbindFromRenderStep("CustomCameraControl")
  64.     RunService:UnbindFromRenderStep("DefaultCameraControl")
  65.     RunService:UnbindFromRenderStep("DeathCameraControl")
  66.     RunService:BindToRenderStep("DefaultCameraControl", Enum.RenderPriority.Camera.Value - 5, defaultRenderStep)
  67.     print("DEFAULT CAMERA DONE!")
  68. end
  69.  
  70. -- ####################################################################################################################################
  71. -- the other file
  72.  
  73. local function initCharacter(Character) -- Connect()ed to event: player.CharacterAdded
  74.     bInited = true
  75.     Controls.updateCharacter(Character) -- ensure the controller has the right character
  76.     Controls.DefaultCamera()   -- set the default camera
  77.    
  78.     --
  79.     -- add things to PartVisibility, not relevant
  80.     --
  81.    
  82.     Character.Humanoid.Died:Connect(function()
  83.         warn("Death!")
  84.         Controls.DeathCamera()
  85.     end)
  86. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement