Hello.
Since I am pretty bad with viewort frame, I decided to open this topic.
So i’m trying to render a camera view in a viewport frame (something like in the image below)
But from what I’ve seen so far, only the player character or a part is rendered. I know that it has a “CurrentCamera” property but I don’t really know how to use it. Any idea?
After a little bit of playing around I’ve managed to get this working. I’d like to give thanks to @XAXA for their SkyBox model (which can be used to emulate skyboxes in WorldModels).
Here’s the script I wrote.
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
player.CharacterAppearanceLoaded:Wait()
local clientCamera = workspace.CurrentCamera
local gui = script.Parent
local viewportFrame = gui:WaitForChild("ViewportFrame")
local worldModel = viewportFrame:WaitForChild("WorldModel")
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
task.wait(1)
character.Archivable = true
local characterClone = character:Clone()
characterClone.Parent = worldModel
characterClone.Humanoid.NameDisplayDistance = 0
characterClone.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Subject
run.RenderStepped:Connect(function()
characterClone:PivotTo(character:GetPivot())
viewportCamera.CFrame = clientCamera.CFrame
end)
Here’s the model file if you’d like to see how everything is organised: model.rbxm (8.2 KB)
Okay, so I know this is a somewhat old post, but I was wondering, after a while the model stops working… Any reason why? I am a beginner scripter/GUI designer and would really appreciate the reply!