How to use viewportframe

Hello, I have a viewportframecamera and I had a camera. I set the viewportframe’s “currentCamera” to the camera then I am inserting parts into the viewportframe to display in my shop. I am trying to make a script that automatically adjusts the position of the part and its rotation in the viewportframe camera so that they are all correctly in picture. What is a script I can use to automatically adjust the parts rotation and position to fit in the picture regardless of the objects size?

I don’t have a script to provide except for

local viewportframe  = script.Parent
local camera = script.Parent.Parent.Camera
local part = script.Parent.Parent.Part
local rand = math.random(1,10)

part.Parent = viewportframe
part.Size = Vector3.new(rand,rand,rand)
--// sets size to random to represent that I want it to be same regarldess of size

--add code here to adjust the position and rotation to be the same regardless of size

Have you tried setting the Focus argument to the Model? That should work, if it doesn’t change the position and you’re done

  1. there is no focus arguement to “model”
  2. the focus arguement of camera requires a position and orientation however I am asking for it to be automatically done with a script so I don’t manually enter positions
  3. I remember doing this long ago with a script but I forgot how
  4. If you’re reffering to the “camerasubject” property of camera then know I tested and it doesnt worrk

Meant the Camera

You would do something like:

camera.Position = model.Position -/+ Vector3.new/CFrame.new(depends,depends,depends)
camera.Orientation = Vector3.new/CFrame.new(depends, depends, depends)

Okay

Not taking about that, if I’m not wrong there should be a focus property, like when you press F in Studio and you have a model/basepart selected

I said regardless of size. Your method will not work

You will need some kind of equation, I’m not sure if there’s a way of doing that that’s 100% sure, you would do something like:

camera.Position = model.Position -/+ Vector3.new/CFrame.new(model.Size * 2,depends,depends)

Just an example, you 100% need an equation, I’m not sure if there’s a way of doing it without an equation

camera.Focus.Position = object:GetPivot().Position + Vector3.new(object:GetPivot().Position * 2, 0, 0)
  22:10:47.969  Position cannot be assigned to  -  Client - build:120

I’m not sure what the problem may be, I’ll check my computer ASAP

local clone = data.Template:Clone()
clone.Parent = data

local object = game.ReplicatedStorage.Info[v.Name][A.Name].Lv1:Clone()
object.Parent = clone.ViewportFrame
					
local camera = Instance.new("Camera")
camera.Parent = clone
					
clone.ViewportFrame.CurrentCamera = camera
camera.Focus.Position = object:GetPivot().Position + Vector3.new(object:GetPivot().Position * 2, 0, 0)
1 Like

Just tested with Studio’s camera, you apparently need soemthgin called CoordinateFrame, not a Vector3

you mean CFrame? wwwwwwwwwwwwwwwwwwwww

If its CFrame I do

camera.Focus = CFrame.new(object:GetPivot().Position + Vector3.new(object:GetPivot().Position * 2, 0, 0))

I am pretty sure
image
however nothing pops up
image
image

It’s growing an error:
invalid argument, CFrame expected, got Vector3

IDK how to solve this, sorry

Found something that could be useful:

yes I know. I know what a CFrame is.

camera.Focus = CFrame.new(object:GetPivot().Position + Vector3.new(object:GetPivot().Position * 2, 0, 0))

image

is a CFrame or coordinateFrame

What, the Camwra is under the Frame? If I’m not wrong taht doesn’t work, could be me tho

Okay, then I think you need to get the primary parts position, like:

camera.Position = model.PrimaryPart.Position + CFrame.new(model:GetPivot.Position * 2, 0, 0)

You cannot add a vector3 to a CFrame. You also cannot set the position to a CFrame.

to set an objects CFrame you do

object.CFrame = (cframe)

in the case, you are only able to set the cameras focus to a CFrame and not vector3. A CFrame is the combination of both a vector3 position and a orientation into one thing.

to manage a CFrame you can do

CFrame = CFrame.New(Vector3.new(pos,pos,pos)) * CFrame.Angles(Vector3.new(orientation,orientation,orientation))

Forgot that the pivot used Vector3, simply use the PrimaryParts size, taht might work

pivot gives you a CFrame. CFrame.Position gives you a vector3. You may need to read up on how to code for roblox.

for beginners like you!

1 Like

This module seems to do what you’re asking for, with an explanation here