Hello!
I am looking to dynamically change this viewport’s FOV but the problem is that I am not sure how I would go about getting the math for it?
My viewport’s current FOV is 45º and it works fine for large accessories, but for small accessories, it’s basically invisible. Any ideas?
Tiny accessory:
Large accessory:
Also should add that in my script, I do get the bounding box of the accessory to render it properly in the viewport, however I am unsure as to how I would approach decreasing/increasing the field of view of the camera accurately based on the size of the accessory.
Script:
local newObject = Instance.new('Model')
local boundingBox = Instance.new('Part')
for i,v in pairs(selectedObject.Value:GetDescendants()) do
if v:IsA('BasePart') then
local clonedObject = v:Clone()
clonedObject.Parent = newObject
clonedObject.Anchored = false
end
end
local cframe, size = newObject:GetBoundingBox()
boundingBox.CFrame = cframe
boundingBox.Size = size
boundingBox.Parent = newObject
boundingBox.Transparency = 1
boundingBox.Anchored = false
boundingBox.CanCollide = false
newObject.PrimaryPart = boundingBox
for i,v in pairs(newObject:GetChildren()) do
if v:IsA('BasePart') then
local weldConstraint = Instance.new('WeldConstraint')
weldConstraint.Parent = v
weldConstraint.Part0 = boundingBox
weldConstraint.Part1 = v
end
end
newObject:SetPrimaryPartCFrame(weldPart.CFrame)
local weldConstraint = Instance.new('WeldConstraint')
weldConstraint.Parent = newObject
weldConstraint.Part0 = weldPart
weldConstraint.Part1 = boundingBox
boundingBox.CFrame = weldPart.CFrame
newObject.Parent = worldModel
oldObject = newObject
Edit: I was thinking I would be able to use the size of the Y axis of the model’s bounding box so I looked up how to find the angle between two vectors but there’s an issue: I have no idea how to use the formula, nor do I know how to translate it into 3D space as I’m not a mathematician. Any ideas?
Edit 2: I forgot to include the camera’s position, its position is 0,5,10 and the orientation in degrees is -26.569999694824, 0, 0
Edit 3: I’ve just tried :WorldToScreenPoint and :WorldToViewportPoint and they ended up being inaccurate, no idea how to proceed. Any help would be really appreciated.