Same view of multiple items in different viewport frames

Hello, I am currently trying to make a shop gui that has, what ive called, cards that have a viewport frame in each that shows a view of the item that that card is resembling. However, I am not very good at using viewport frames and currently I can not work out how to get the views on all the cards to look the same. Here is what currently happens:
image
2 Completely different views.

This is what I want it to look like: (This pic is edited)

This is my current script:

local UICARD = RS:WaitForChild("Templates"):WaitForChild("Card_Temp"):Clone()
UICARD.Parent = script.Parent:WaitForChild("BG"):WaitForChild("Cards")
UICARD.Name = v.Name

local CardInfo = UICARD:FindFirstChild("INFO")
local RodViewport = UICARD:FindFirstChild("RodView")

local viewportCamera = Instance.new("Camera")
viewportCamera.Name = "Cam"
viewportCamera.Parent = RodViewport

RodViewport.CurrentCamera = viewportCamera

local RodClone = v:Clone()
RodClone.Parent = RodViewport:FindFirstChild("WorldModel")
RodClone.PrimaryPart = RodClone:FindFirstChild("Handle")
local cframe, size = RodClone:GetBoundingBox()
local position = cframe.Position
local offset = Vector3.new(size.X * 0.4, size.Y * 0.2, size.Z * 2.5)
viewportCamera.CFrame = CFrame.lookAt(position + offset, position)

UICARD:FindFirstChild("RodName").Text = v.Name
CardInfo:FindFirstChild("Range").Text = "Range: " .. tostring(v:FindFirstChild("Config"):FindFirstChild("Range").Value)
CardInfo:FindFirstChild("MaxRarity").Text = "Max Rarity: " .. tostring(v:FindFirstChild("Config"):FindFirstChild("MaxRarity").Value)
UICARD:FindFirstChild("Buy//Equip"):FindFirstChild("Price/EquipDisp").Text = "BUY: " .. tostring(v:FindFirstChild("Config"):FindFirstChild("Price").Value) .. "$"

Any help would be much appreciated!

2 Likes

I would take a quite similiar route for the camera repositioning, with just a little difference.
Here it is how I would do it:

  1. Set the cloned model’s orientation inside the ViewportFrame to a vertical position (it could be
    Vector3.new(0, 90, 0) or even slightly inclined towards one line, but make sure to have one dimension completely perpendicular to the ground) (this will make the offset calculation and camera positioning easier)
  2. Take the CFrame and the size of the bounding box
  3. Calculate the offset (this is up to you, and your current formula should work good)
  4. Set the camera CFrame to BoundingBoxCFrame + offset

This should work, and make the calculation a little easier :+1:

2 Likes

Hi, replying a little bit late as have been busy recently. Doing what you have recommended gets me to this:

Could you show me the new code?

local RodClone = v:Clone()
RodClone.Parent = RodViewport:FindFirstChild("WorldModel")
RodClone.PrimaryPart = RodClone:FindFirstChild("Handle")
RodClone.PrimaryPart.Position = Vector3.new(0, 0, 0)
RodClone.PrimaryPart.Orientation = Vector3.new(0, 90, 0)
local cframe, size = RodClone:GetBoundingBox()
local position = cframe.Position
local offset = Vector3.new(size.X * 0.3, size.Y * 2.5, size.Z * .3)
viewportCamera.CFrame = CFrame.lookAt(cframe.Position + offset, position)

At line 5,

RodClone.PrimaryPart.Orientation = Vector3.new(0, 90, 0)

the Vector3 should be different. Try different combinations (example: (180, 0, 0) , (0, 180, 0) , (0, 0, 180) … ).
Let me know if it works :+1: