Hello, this is my first time using viewportframes and i want to ask some basic questions. I have this viewport and i want it to display a model. I set a part named root that is the models exact center and made the viewport that position. This is my code:
local template = script.Parent.Parent.Template:Clone() -- the viewport
local Info = string.split(info, " ")
template.Parent = game.Players.LocalPlayer.PlayerGui.ScreenGui
local part = game.Workspace.ImageInfo:FindFirstChild(Info[1]):Clone()
part.Parent = workspace
local viewportCamera = Instance.new("Camera")
template.CurrentCamera = viewportCamera
viewportCamera.Parent = template
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 2, 12), part:FindFirstChild("Root").Position)
however it only displays this from the code:
one thing I’m thinking is it’s displaying the root part which is about vector3.new(0.01,0.01,0.01) which would be to small to appear visible. If that’s the case how would i display a model with viewport if i cant get the models position?
I’m thinking it’s displaying the root part which is about vector3.new(0.01,0.01,0.01) which would be too small to appear visible. If that’s the case how would I display a model with viewport if I cant get the models position?
calls for a position which models don’t have
(I’m going off documentation… I have no idea how viewport works. maybe using position is just to get a size? even if that’s the case I can’t get the size of a model)
That all depends on the correct positioning of the camera and as i said you will need to modify the second parameter to best frame the model, You will basically need to move the camera a bit behind the model’s position
i have 138 models I wont be able to correctly position the camera for all 138 models without making my code
A. look dog trash
and
B. take me like 9 hours
The first parameter to CFrame.new() will position the camera exactly at the center of the model/part so you will definitely need to move the camera behind (using the second parameter which is a lookAt Vector3) of half the model’s X size (if the camera frames the part from the X axis, if it frames the part form the Z axis you will need to move the camera behind of half the model’s Z size) but that will put it very near the model so you will need to add a bit more studs