Hello! For the past hour I have scoured this forum and other sources for help with my specific problem. Basically, I have a camera inside a viewport frame that uses a camera PART in the workspace to position itself as eventually a player will move this camera, in turn changing the perspective of the viewport frame.
Currently, everything works fine except the fact that my viewport camera isn’t setting the position and orientation from the WORKSPACE camera. Below is my localscript which is in starterplayerscripts for now. How the current system works is that it clones everything from a folder in workspace (which contains everything “in-scene”) to inside the viewport frame. I have it set up to show the baseplate and the tree so far, except as described earlier it doesn’t show the tree and seems to have a mind of it’s own and sets to it’s own position and orientation.
The grey floating part is the camera, the red part can be ignored for now. You can also then see what happens when I view the viewport frame:
As you can see, this is very much angled and higher than the actual position of the WORKSPACE camera.
Also, I am well aware of the lag this way of doing it may cause however I would prefer to get it working first.
I hope you all understand and help would be much appreciated.
I’m new to vector3 and cframe stuff so I’m sorry if I’m just being stupid.
LocalScript in StarterPlayerScript:
local ui = Instance.new("ScreenGui")
ui.Parent = game.Players.LocalPlayer.PlayerGui
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0, 480, 0, 270)
viewportFrame.Position = UDim2.new(0, 0, 0.52, 0)
viewportFrame.Parent = ui
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
local scene = game.Workspace.Scene:GetChildren()
for i,v in pairs(scene) do
local clone = v:Clone()
clone.Parent = viewportFrame
end
viewportCamera.CameraType = Enum.CameraType.Scriptable
while true do
wait(.017)
local camposition = Vector3.new(game.Workspace.TestCam.CAMERA.Position)
local camrotation = Vector3.new(CFrame.Angles(math.rad(game.Workspace.TestCam.CAMERA.Orientation.X), math.rad(game.Workspace.TestCam.CAMERA.Orientation.Y), math.rad(game.Workspace.TestCam.CAMERA.Orientation.Z)))
viewportCamera.CFrame = CFrame.new(camposition, camrotation)
end