Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CameraTurnScript
- local UserInputService = game:GetService("UserInputService")
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- -- Define the key you want to use to turn the camera (e.g., "R")
- local TURN_KEY = Enum.KeyCode.Space
- local originalCameraCFrame
- local isTurning = false
- local function onKeyPress(input, gameProcessed)
- if gameProcessed then
- return
- end
- if input.KeyCode == TURN_KEY then
- -- Store the original camera orientation if not already turning
- if not isTurning then
- originalCameraCFrame = Camera.CFrame
- isTurning = true
- end
- -- Calculate the new camera orientation by rotating 180 degrees around the Y-axis
- local newCameraCFrame = originalCameraCFrame * CFrame.Angles(0, math.rad(180), 0)
- -- Set the camera to the new orientation
- Camera.CFrame = newCameraCFrame
- end
- end
- local function onKeyRelease(input, gameProcessed)
- if gameProcessed then
- return
- end
- if input.KeyCode == TURN_KEY and isTurning then
- -- Restore the original camera orientation
- Camera.CFrame = originalCameraCFrame
- isTurning = false
- end
- end
- -- Connect the input events to the functions
- UserInputService.InputBegan:Connect(onKeyPress)
- UserInputService.InputEnded:Connect(onKeyRelease)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement