Advertisement
Guest User

Camera Turn Script

a guest
May 26th, 2024
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. -- CameraTurnScript
  2. local UserInputService = game:GetService("UserInputService")
  3. local Players = game:GetService("Players")
  4. local LocalPlayer = Players.LocalPlayer
  5. local Camera = workspace.CurrentCamera
  6.  
  7. -- Define the key you want to use to turn the camera (e.g., "R")
  8. local TURN_KEY = Enum.KeyCode.Space
  9.  
  10. local originalCameraCFrame
  11. local isTurning = false
  12.  
  13. local function onKeyPress(input, gameProcessed)
  14. if gameProcessed then
  15. return
  16. end
  17.  
  18. if input.KeyCode == TURN_KEY then
  19. -- Store the original camera orientation if not already turning
  20. if not isTurning then
  21. originalCameraCFrame = Camera.CFrame
  22. isTurning = true
  23. end
  24.  
  25. -- Calculate the new camera orientation by rotating 180 degrees around the Y-axis
  26. local newCameraCFrame = originalCameraCFrame * CFrame.Angles(0, math.rad(180), 0)
  27.  
  28. -- Set the camera to the new orientation
  29. Camera.CFrame = newCameraCFrame
  30. end
  31. end
  32.  
  33. local function onKeyRelease(input, gameProcessed)
  34. if gameProcessed then
  35. return
  36. end
  37.  
  38. if input.KeyCode == TURN_KEY and isTurning then
  39. -- Restore the original camera orientation
  40. Camera.CFrame = originalCameraCFrame
  41. isTurning = false
  42. end
  43. end
  44.  
  45. -- Connect the input events to the functions
  46. UserInputService.InputBegan:Connect(onKeyPress)
  47. UserInputService.InputEnded:Connect(onKeyRelease)
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement