Hello,
I am working on a system for my game, and it requires a model in a viewport. However, I got the viewport itself to work, but I cannot get it to face/fit the whole frame. As you can see in the game picture below, it’s very zoomed out. The other picture of the pipboy 2000 is how I want the model to fit the viewport. Here is my code:
It really should because it will fit the model regardless of the orientation.(if the pivot point is correct)
Or if you want a simpler method then just use simple trigonometry.
I understand that, but its really complicated and it is constantly turning and I am not well acquainted with module scripts and it’s not what I am looking for. I do not know what trigonometry is.
Where L is the longest length. O is opposite and A is adjacent. The FOV is halved to make a right angled triangle. Find out A to get the required distance for the whole model to fit.
Rearrange to get a.
local FOV =
local L =
local D = (0.5*L)/(math.tan(math.rad(FOV/2))
-- and if you want to change the FOV instead then
FOV = math.deg(math.atan((L*0.5)/D)))
--but L and D are required.
You could create a viewport, then have a worldModel inside of it with a Camera.
Then simply →
ContainerClone:WaitForChild("Viewport").WorldModel.PrimaryPart = ToolPreview.Handle
ToolPreview.Parent = ContainerClone:WaitForChild("Viewport").WorldModel
if not ContainerClone.Viewport:FindFirstChildOfClass("Camera") then
local Camera = Instance.new("Camera")
Camera.Parent = ContainerClone.Viewport.WorldModel
local CameraPosiiton = (CFrame.new(ToolPreview.Handle.Position)).Position
Camera.CFrame = CFrame.new(ToolPreview.Handle.Position + ToolPreview.Handle.CFrame.LookVector * 5, ToolPreview.Handle.Position)
ContainerClone.Viewport.CurrentCamera = Camera
ContainerClone.Parent = Container
if not ToolPreview:FindFirstChild("PartRotate") then
local ScriptClone = script:WaitForChild('PartRotate'):Clone()
ScriptClone.Parent = ToolPreview
end
end
A friend helped me with this, and it may be resourceful to you.
I tried this script and messed around with it and didn’t work. I tried making the code work but theres no errors but it just doesn’t appear in the viewmodel.