So I’ve been messing around with view port frames in tooltips but can’t get everything to work regardless of what model is put in the viewport frame. I have taken some precaution to scale the models to be the same size and fit the but it is a little complicated and sometimes different models end up rotating differently. The script rotates 1 degree on the X axis per wait() and works great for this greatsword model but when I put in my fist gloves, it rotates vertically instead of horizontally. I tried manipulating the axis of the model but I can’t figure out any way to make it rotate the same way Any help?
To fix the rotating on the wrong axis issue, You can change the pivot of the model that rotates. (To do this, just go into the model tab and select edit pivot when the model is selected)
local Part = script.Parent:FindFirstChildOfClass("Model")
local ViewportFrame = script.Parent-- Viewport Frame Here.
local Camera = Instance.new("Camera")
Camera.Parent = ViewportFrame
Camera.CFrame = CFrame.new((Part.PrimaryPart.CFrame * CFrame.new(0,0,-8)).Position + Vector3.new(4,0,0), Part.PrimaryPart.Position)
ViewportFrame.CurrentCamera = Camera
local primaryPart = Part.PrimaryPart
local function calculateFov(partSize, viewportSize)
local maxDimension = math.max(partSize.X, partSize.Y)
local viewportMaxDimension = math.max(viewportSize.X, viewportSize.Y)
local fov = math.atan(maxDimension / (viewportMaxDimension / 2)) * (180 / math.pi) * 2
return fov
end
Camera.FieldOfView = calculateFov(Part.PrimaryPart.Size,ViewportFrame.AbsoluteSize) + 15
local function rotateModel(rotation)
local primaryCFrame = primaryPart.CFrame
local newCFrame = primaryCFrame * rotation
for _, parts in Part:GetChildren() do
if parts:IsA("BasePart") then
local offset = primaryCFrame:toObjectSpace(parts.CFrame)
parts.CFrame = newCFrame * offset
end
end
end
while wait() do
rotateModel(CFrame.Angles(math.rad(1), 0, 0))
end
here is the code I use for the viewport, do you see anything that could contradict?
If it works properly for some models but not for others then it’s not an issue with the script. If editing the pivot didn’t work then try adding tags to the models that the script checks for (Like RotY or RotZ) and rotates them on the tagged axis.
Try creating a Part and place it near the Model. Then, rotate the Model to whatever angle you want. Afterward, put that Part into the Model.
Now, for the rotation script. set the Model’s PrimaryPart to the Part
you just created. Using :PivotTo(PrimaryPart.CFrame*CFrame.Angles()), the Model should rotates relative to the Part while maintaining the desired angle.
Now I’m having a different problem, the Y axis is now in the right spot (I believe) but it is being rotated on the X axis even when the script alters the Y
But the viewport still rotates it along the X axis both in the frame and in its properties so it only briefly stays upright and you can never see the side view of the item.