Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you detect when the camera is at a certain orientation?

Asked by 3 years ago
Edited 3 years ago

I'm trying to rotate the camera 90° and then rotate it -180° then rotate it 180°

Code:

local goingback = false
local Player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local character = Player.Character or Player.CharacterAdded:Wait()

local camera = workspace.CurrentCamera

repeat wait()
    camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = workspace.PushTheButton.Base.CFrame + Vector3.new(10,0,0)
camera.CFrame = camera.CFrame * CFrame.Angles(math.rad(90), math.rad(-180), math.rad(-90))

RunService.RenderStepped:Connect(function()
    if camera.CFrame.RightVector.Z <= 0 and goingback == false then
        camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(1))
    else -- this is where I want to detect when it is at a certain orientation
        goingback = true
        camera.CFrame = camera.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(0), math.rad(-1))
    end
end)

Answer this question