I am trying to place a model into a viewport frame however it doesnt work how I want it to…
I want it to be a good picture of a computer that I put into it.
I have tried commenting out
part.Position = Vector3.new(0, 0, 0)
but it looks like this when I do
and when I dont comment it out it looks like this
but the model that should be showing is this and I have no idea why it shows that-
The script:
function viewPortCamera(frame,model)
local viewportFrame = Instance.new("ViewportFrame")
viewportFrame.Size = UDim2.new(0, 208,0, 141)
viewportFrame.Position = UDim2.new(0,0,0,0)
viewportFrame.BackgroundTransparency = 1
viewportFrame.Parent = frame
local part = model.ViewportPart
part.Position = Vector3.new(0, 0, 0)
model:Clone().Parent = viewportFrame
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 2, 5), part.Position)
end
for _,v in pairs(game.ServerStorage.Setups:GetChildren()) do
if v.ClassName == "Model" then
if script.Parent:FindFirstChild("Template") then
script.Parent["Template"].Buy.Text = v.Cost.Value.." R$"
script.Parent["Template"].LayoutOrder = v.Cost.Value
viewPortCamera(script.Parent["Template"],v)
script.Parent["Template"].Name = v.Name
else
for _,f in pairs(script.Parent:GetChildren()) do
if f:FindFirstChild("Template") then
local clone = f:Clone()
clone.Name = v.Name
clone.Buy.Text = v.Cost.Value.." R$"
clone["Template"]:Destroy()
clone.LayoutOrder = v.Cost.Value
clone.Parent = script.Parent
viewPortCamera(clone,v)
end
end
end
else
print(v.Name.." is not a model.")
end
end
Well, This is moving your model 10 studs in front of the camera(viewport camera) as mentioned, if this wasn’t what you were looking for, then please re-explain it for me.
And where would this go? I don’t think I have a variable named ViewPortCFrame, but if I did, just using “+” would not add them so that also confuses me.
local ModelSize = Model:GetExtentsSize() -- Get the size of our model in all axis. (Like saying Part.Size, just on a model)
local ViewportCFrame = ViewportCamera.CFrame -- ViewportCFrame is actually just our viewport cameras CFrame.
Model.CFrame = ViewportCFrame + ViewPortCFrame.LookVector*(Offset+(ModelSize.Z/2)) -- Let's take this one in steps:
-- Step 1: "ViewportCFrame" Do so our Model's CFrame is the same as our ViewportCFrame.
-- Step 2: "ViewPortCFrame.LookVector" We prepare to move the Model in the direction of where the Camera is looking. Since LookVector is the forward direction of a object.
-- Step 3: "Offset" is how far away from the Camera we want our Model to be placed.
-- Step 4: "ModelSize.Z/2" Here we're getting the Model's Size in the Z axis (before rotating it and such), and then taking half that size, and adding it to our offset. That does so that no matter of small or large our object is, it will keep the offset at the offset amount we've chosen.
Ok it makes me feel REALLY guilty to say this and also REALLLLY bad but I decided to close the support thread because I found a viewport generator plugin (already scanned for viruses) and I just decided to use that. I will give you the solution tho for all your help. Ty.