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)
Do I have to save the pivot or something? I change the X axis (red) to be horizontal like such
but after I put it back in the viewport it returns to the old pivot
When I click Edit pivot again, it reverts it back to the correct one only while im editing the pivot
Just had to hit CTRL + L but it still rotates vertically within the viewport frame…
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?
bump cause i still cant rotate this right
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.
edit: wrong method for the model
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
rotateModel(CFrame.Angles(0, math.rad(1), 0))
But the viewport still rotates it along the X axis both in the frame and in its properties
