How do I keep the part the same relative position and size with different FOV?

So I’ve started experimenting with 3D UI’s and I’m really liking how its turning out and I’ve got it working great up until this point but, there is something I need to do with the camera’s FOV (decrease it), but the problem is that the UI doesnt exactly I guess scale properly?

I’m using ScreenToPointRay and using what it returns as the position for the part that is displaying the UI

What it looks like at 70 FOV

What it looks like at 30 FOV

Heirachy:
image

Code I use for positioning it:

local ray = camera:ViewportPointToRay(camera.ViewportSize.X/2, camera.ViewportSize.Y/1.2, -10)
Dialogue.CFrame = CFrame.new(ray.Origin + ray.Direction)

Maybe I need to like actually resize the part and take into account the camera’s field of view?

1 Like

maybe just times the overall scale of the object by the current like you said. There probably is a more automated solution but its the easiest to implement

local orgSize = Dialogue.size -- make sure to set this earlier in the script

local ray = camera:ViewportPointToRay(camera.ViewportSize.X/2, camera.ViewportSize.Y/1.2, -10)
Dialogue.CFrame = CFrame.new(ray.Origin + ray.Direction)
local fovScale = Camera.FieldOfView * (scale) -- you need to find the scale your self
Dialogue.Size = orgSize * Vector3.new(orgSize.X * fovScale, orgSize.Y*fovScale, orgSize.Z * fovScale)