How would I code a viewport frame?

I have no experience with viewport frames. I’m currently using screenshots of items to display them in my game’s menu, but I wanted to see if positioning a camera at the item’s model would work better. I heard they were very laggy, but I still want to try them as taking and editing screenshots is a pain. Where would I start?

3 Likes

You’d start from a Youtube video. How To Use Viewport Frames | Roblox Studio - YouTube
I’m sure I’ve seen many use cases of this (e.g shop menus, inventories), with no lag at all. You should be able to figure everything out with a couple Google searches.

2 Likes

Viewport frames have the same performance as ImageLabels when they aren’t being redrawn. They only get redrawn when its descendants change/update, or when the camera changes position.

1 Like

Here’s something to start:

local viewport = -- Path to viewport
local viewportCamera = Instance.new("Camera")
viewportCamera.CFrame = CFrame.new(0, 0, -5) -- Adjust
viewportCamera.Parent = viewport
viewport.CurrentCamera = viewportCamera
local viewportModel = model:Clone() -- Replace model with path to desired model
viewportModel:PivotTo(CFrame.new(0, 0, 0))
viewportModel.Parent = viewport

For the advanced stuff I recommend using EgoMoose’s viewport fitter module:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.