Properly Aligning Viewport Frame

I’ve been working on making a new inventory system for my game and have had numerous problems with ViewportFrames and trying to draw out my items.

I’m trying to render a sword similar to how this twitter post has it.

This is the code I’m using…

function Inventory:Draw()
	itemData = {}
	local contents = self.Events.GetInventory:InvokeServer()
	for itemName,itemAmount in pairs(contents) do
		local itemTable = self.Shared.Items[itemName]
		local count = 0
		for i,v in pairs(itemsList:GetDescendants()) do
			if v.Name == "Item" and v.Parent.Name == "Row" and not itemData[v] then
				itemData[v] = itemTable
				local model, primary
				if not itemTable.Model then
					if itemTable.Tool then
						model = itemTable.Tool
						primary = model.Handle
					end
				else
					model = itemTable.Model
					primary = model.PrimaryPart or model:WaitForChild("Hitbox") or nil
				end
				if primary then
					model = model:Clone()
					model.Parent = v.Showcase
					
					local viewportCamera = Instance.new("Camera")
					v.Showcase.CurrentCamera = viewportCamera
					viewportCamera.Parent = v.Showcase
					
					viewportCamera.CFrame = CFrame.new(primary.CFrame:toWorldSpace(CFrame.new(0,1,-2)).p, primary.Position)
				end
				break
			end
		end
	end
end

And here is the outcome of it…

I have rotated the sword thousands of times and have no good outcome from this. I’ve also adjusted the offsets, etc… and have had no luck. Each time its just a blob that looks awful.

3 Likes

You’ll could manually set the camera’s offset. The sword is thin, so you should only show a small part of it (the handle?).