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

Why the camera is glitching when the rotation is made?

Asked by 8 years ago

It starts being glitchy when you touch the brick, it tries to change to the new angle, but then it goes back to the last one, and it doesn't stop doing that, some help?

local changecam = game.Workspace.Change
local touched = false
-- ================================================================

-- // Camera Variables

local CamOffset = Vector3.new(0, 5.5, 20)
local CamLookDirection = Vector3.new(0, 0, -1)
local angle = 0

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local RunService = game:GetService('RunService')


-- ================================================================


changecam.Touched:connect(function(hit)
    if not touched then

        touched = true
        wait(1)
        print("I touched it!")
         local function setupCamera()
            camera.CoordinateFrame = CFrame.new(player.Character.HumanoidRootPart.Position + CamOffset,
                             player.Character.HumanoidRootPart.Position + CamOffset + CamLookDirection)
        end 

        player.CharacterAdded:connect(setupCamera)
        print("1")

          local function onUpdate()
            if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then
        camera.CoordinateFrame = camera.CoordinateFrame:lerp(
                                 CFrame.new(player.Character.HumanoidRootPart.Position + CamOffset,
                                 player.Character.HumanoidRootPart.Position + CamOffset + CamLookDirection), 0.2 )
        print("Trying to rotate")    
    for i = 1, 90 do
        wait()
        camera.CFrame = camera.CFrame * CFrame.Angles(0,i,0)
    end
        end
    end
        RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
    print("2")

        touched = false     

    end
end)


Answer this question