Spinning Item in Viewport

Hello, I am trying to make a shop with viewports and the items inside spinning, but every item spins differently I have been trying for so long.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ViewportModule = require(ReplicatedStorage:WaitForChild("ViewportModule"))
local RunService = game:GetService("RunService")

for _, viewport in ipairs(script.Parent:GetChildren()) do
	if viewport:IsA("ViewportFrame") then

		task.spawn(function()
			local model = viewport:FindFirstChildWhichIsA("Model")
			if not model then return end

			local camera = Instance.new("Camera")
			camera.Parent = viewport
			viewport.CurrentCamera = camera

			local boxCFrame = model:GetBoundingBox()
			model:PivotTo(boxCFrame)

			model:PivotTo(model:GetPivot() * CFrame.Angles(
				math.rad(-20),
				math.rad(-45),
				math.rad(-90)
				))

			local viewportModel = ViewportModule.new(viewport, camera)
			viewportModel:SetModel(model)

			local pivotPosition = model:GetPivot().Position

			local angle = 0
			RunService.RenderStepped:Connect(function(dt)
				angle += math.rad(90) * dt
				model:PivotTo(
					CFrame.new(pivotPosition) * CFrame.Angles(0, 0, angle)
				)
			end)

			camera.CFrame = viewportModel:GetMinimumFitCFrame(CFrame.new())
		end)
	end
end


I like the one on the right spinning like that but I need it diagonal and the one on the left is just wrong I want it diagonal bottom left to top right and spinning.

I have no idea how to do this please help

2 Likes

In the models of the items, can you set the Pivot Offset on Position and Orientation to 0, 0, 0 regardless of the actual CFrame of the model? If this impacts your game, you can also do it when you clone the model into the viewport via the script.

image

1 Like

Just mess with the Pivot Offset during Playtesting to find what you like. Everytime you change it, edit the model orientation (not pivot one) to add a space after it in order to quickly reset the model’s orientation data to see the effects of editing the pivot. That way you can preview it quickly during testing. When you find the values for what you sought, copy and paste the orientation offsets into your model from playtesting to studio.

1 Like