Scale block based on cameraFOV

i have recently finished recoding my 3D ui system for my game from the ground up, but i found a problem
it cannot rescale based on the fov! and a class im working on have to be able to scope in!


how can i fix this?

3 Likes

are they surfaceguis attached to the camera?

2 Likes

their position are calculated based on the camera position and size, yea

local viewportSize = camera.ViewportSize
	local RayPlacement = camera:ViewportPointToRay(viewportSize.X * (position.X/units), viewportSize.Y * (position.Y/units), position.Z)
	local place = RayPlacement.Origin + RayPlacement.Direction
1 Like

i have an idea but i am not sure if it is the best solution, try putting them in a viewport frame in the playergui

1 Like

im almost sure it would make the buttons not be able to be clickable anymore, and its meant to be mobile compatible

1 Like

i doubt this will work, but i had the idea to use something similar to the rule of threes

1 Like

viewportFrame didnt work as it cant render surface GUI, and my proportion idea didnt work as it didnt succesfully keep the rotation


1 Like

bump, this might be a bigger problem than i thought :confused:

1 Like

Angular diameter might be what your looking for?

theta = arctan(d/2D)

d is your diameter or scale of object. D is distance from the object.
theta would be the fov.

1 Like

You can rewrite this as
image

Maybe I’m stupid, but that’s my logic lmao

d is the object scale. D is the distance, theta is the fov

or just solve for d (object scale) instead

1 Like

so the d scale is the size magnitude? D would be the Z position I would assume

Yeah it terms of CFrames then D would be Z. d is really something you gotta tamper with, I would use that as a scale value, so the original size of the object at x fov would be your initial scale of 1, and then you go from there.

E.g

Calcuation : 70 FOV at 5 distance = initial scale.
Next calculation : 70 FOV at 6 distance = initial scale - new calcuation (this way you can get the variance)

ok so i have to find the d scale using the same calculation? i changed it to be ( default distance ) / 2*math.tan(math.rad( default FOV )), which resulted in 1.0919107027986072, so i find the variance then multiply the size or the Z distance by this?

edit: ok i think it would be distance because size wouldnt work

@paswa a little too much…