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

How to set CFrame of the ViewportFrame camera to the CFrame of the main camera?

Asked by
sssynk 58
5 years ago

Hello all, so today I am trying to match up the ViewportFrame camera with the main camera by setting it's CFrame. I have code attached. The script is the child of the ViewportFrame.

wait(3)

while 2+2==4 do

local viewportFrame = script.Parent

local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame

local camera = workspace.CurrentCamera
local cameraCFrame = camera.CFrame
local viewCFrame = viewportCamera:GetRenderCFrame()

viewportCamera.CFrame = CFrame.new(Vector3.new(cameraCFrame))
print(viewCFrame)
wait(0.1)


end

Thank you! Any help is appreciated.

0
Sorry if my code is messy. I am new to Lua! sssynk 58 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

It's actually quite simple! You just need to set the ViewportFrame's CurrentCamera to the current camera in workspace with a LocalScript.

script.Parent.CurrentCamera = workspace.CurrentCamera --Set the CurrentCamera of the ViewportFrame as the CurrentCamera in workspace
0
Thanks! Way easier than expected! sssynk 58 — 5y
Ad

Answer this question