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

How to return the camera?

Asked by 9 years ago

I have made a main menu and the camera is in the sky like a cutscene however i do not know how to make it so it returns to the player i will add the camera script if you need it for anything.

repeat wait () until game.Workspace.CurrentCamera ~= nil

local c = game.Workspace.CurrentCamera
local data = LoadLibrary("RbxUtility").DecodeJSON(script.CutsceneData.Value)
local rs = game:GetService("RunService").RenderStepped

function tweenCam(c1,f1,time,fov,roll)
    local c0,f0,fv0,r0,frames = c.CoordinateFrame,c.Focus,c.FieldOfView,c:GetRoll(),time/0.015
    for i = 1,frames do
        c.CameraType = "Scriptable"
        c.CoordinateFrame = CFrame.new(c0.p:lerp(c1.p,i/frames),f0.p:lerp(f1.p,i/frames))
        c.FieldOfView = (fv0+(fov-fv0)*(i*(1/frames)))
        c:SetRoll(r0+(roll-r0)*(i*(1/frames)))
        rs:wait()
    end
end

if script:findFirstChild("SkipCutsceneGuiValue") then
    local gui = script.SkipCutsceneGui:clone()
    gui.Parent = game.Players.LocalPlayer.PlayerGui
    gui.Cutscene.Value = script
    gui.Enter.Debug.Disabled = false
    script.SkipCutsceneGuiValue.Value = gui
end
while true do
    wait()
    c.CameraSubject = nil   
    c.CameraType = "Scriptable"
    c.CoordinateFrame = CFrame.new(unpack(data[1].c1))
    c.Focus = CFrame.new(unpack(data[1].f1))
    c.FieldOfView = data[1].FOV
    c:SetRoll(data[1].Roll)
    for i = 2,#data do
        tweenCam(CFrame.new(unpack(data[i].c1)),CFrame.new(unpack(data[i].f1)),data[i].step,data[i].FOV,data[i].Roll)
    end
end
c.CameraSubject = game.Players.LocalPlayer.Character.Humanoid   
c.CameraType = "Custom"
c.FieldOfView = 70
if script:findFirstChild("SkipCutsceneGuiValue") then
    if script.SkipCutsceneGuiValue.Value ~= nil then
        script.SkipCutsceneGuiValue.Value:Destroy()

end   
end    workspace.Script.destory()       

2 answers

Log in to vote
0
Answered by 9 years ago

From line 25 to line 36, you have an infinite loop. You have to break that loop using break somewhere in your loop's code in order for the code after line 36 to execute.

Another option could be to have a BoolValue object that tells the script whether or not to do the camera work and then add something like this to replace the "while true do" line:

while game.Players.LocalPlayer.BoolValue.Value == true do --Change game.Players.LocalPlayer.BoolValue to the path of your BoolValue.
0
ok ill try it Codboy22 9 — 9y
0
messed it up even more by not working Codboy22 9 — 9y
0
Edited my answer. Spongocardo 1991 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Loop

I have to leave right now, so I'll come back and put an explanation, but you need a break to get out of that infinite loop.

repeat wait () until game.Workspace.CurrentCamera ~= nil

local c = game.Workspace.CurrentCamera
local data = LoadLibrary("RbxUtility").DecodeJSON(script.CutsceneData.Value)
local rs = game:GetService("RunService").RenderStepped

function tweenCam(c1,f1,time,fov,roll)
    local c0,f0,fv0,r0,frames = c.CoordinateFrame,c.Focus,c.FieldOfView,c:GetRoll(),time/0.015
    for i = 1,frames do
        c.CameraType = "Scriptable"
        c.CoordinateFrame = CFrame.new(c0.p:lerp(c1.p,i/frames),f0.p:lerp(f1.p,i/frames))
        c.FieldOfView = (fv0+(fov-fv0)*(i*(1/frames)))
        c:SetRoll(r0+(roll-r0)*(i*(1/frames)))
        rs:wait()
    end
end

if script:findFirstChild("SkipCutsceneGuiValue") then
    local gui = script.SkipCutsceneGui:clone()
    gui.Parent = game.Players.LocalPlayer.PlayerGui
    gui.Cutscene.Value = script
    gui.Enter.Debug.Disabled = false
    script.SkipCutsceneGuiValue.Value = gui
end
while true do
    wait()
    c.CameraSubject = nil   
    c.CameraType = "Scriptable"
    c.CoordinateFrame = CFrame.new(unpack(data[1].c1))
    c.Focus = CFrame.new(unpack(data[1].f1))
    c.FieldOfView = data[1].FOV
    c:SetRoll(data[1].Roll)
    for i = 2,#data do        tweenCam(CFrame.new(unpack(data[i].c1)),CFrame.new(unpack(data[i].f1)),data[i].step,data[i].FOV,data[i].Roll)
    end
break --<
end
c.CameraSubject = game.Players.LocalPlayer.Character.Humanoid   
c.CameraType = "Custom"
c.FieldOfView = 70
if script:findFirstChild("SkipCutsceneGuiValue") then
    if script.SkipCutsceneGuiValue.Value ~= nil then
        script.SkipCutsceneGuiValue.Value:Destroy()

end   
end    workspace.Script.destory()       


Or rather, you don't need the 'while true do' at all. I'll come back and fully explain it even more.

Quick Link

http://wiki.roblox.com/index.php?title=Loops#Break

Answer this question