Hi everyone
I was looking around on the devforum to see if there was any resources for this but there wasn’t.
Let’s say you want to zoom in on the player that killed you once you died from the position you are currently at. There are a lot of games that do this and it’s a very awesome effect.
Here’s a function that can do that for you.
function ZoomFit(Object : Model)
local c = workspace.CurrentCamera
local Orientation, size = Object:GetBoundingBox()
local ObjectRadius = size.Magnitude
--[[Derived from: local dist = radius / (math.sin(math.rad(c.fieldOfView) / 2));]]--
local fov = 114.59155902 * math.asin(ObjectRadius/ (c.CFrame.p - Object.WorldPivot.Position).Magnitude)
c.FieldOfView = fov
c.CFrame = CFrame.lookAt(c.CFrame.Position, Object.WorldPivot.Position);
end
The function will set your Camera’s FOV to fit the entire object (model) in it’s view.
If you are wondering about the random number in the calculation, read the comment above the line.