How do I scale a screen GUI based off the cameras current position?

Im working on a small little project right now. And Im trying to achieve a effect like in this clip.
Clip

The background is blurred out and darkened, the player has emphasis and the effect isnt affected by this blurring.

What im using to achieve this is viewport frames to render the player on a GUI, and ColorCorrection to blur the background. What im having trouble with is the effect. Im using a ScreenGui for the effect that sets its position to the target part. Only thing im having issue with is the scaling. When I zoom out, it grows. but when i zoom in, it shrinks. How could I make it so it shrinks when i zoom out/move away and grow when I zoom in/move closer? Thanks in advance!

EDIT: Actually, the size of the UI doesnt change at all. But I have no idea how to scale it based off my cameras zoom and the players distance from the target part without the position of GUI looking off.

Issue:
Issue

Code:


local character = game.Players.LocalPlayer.Character
local OGSize = script.Parent.Size
while true do task.wait()
	local ZoomLevel = (workspace.CurrentCamera.Focus.Position - workspace.CurrentCamera.CFrame.Position).Magnitude
	local Distance = (character.HumanoidRootPart.Position - workspace.OrbThing.Position).Magnitude
	local vectors, onscreen = game.Workspace.Camera:WorldToScreenPoint(workspace.OrbThing.Position)
	script.Parent.Position = UDim2.fromOffset(vectors.X,vectors.Y)
	
	script.Parent.Size = UDim2.new(OGSize.X.Scale/(ZoomLevel+Distance),script.Parent.Size.X.Offset,OGSize.Y.Scale/(ZoomLevel+Distance),script.Parent.Size.Y.Offset)
end
1 Like

bumping this, still need help!

you can probably use a billboard gui with offset scaling to achieve the same effect

the size should be 1/distance though

Yeah I tried using billboard GUI’s the issue is that it would be affected by lighting. And I have no idea if theres a option to disable it. And I cant put the billboard GUI over the screengui.

There is a property called LightInfluence or something like that.

also, it isn’t shrinking or growing. it isn’t changing size at all.

1 Like

Can I see the properties of the UI itself, namely the size, while runtime probably.

Oh yeah you’re right, im just now realizing it

The size stays the same which I just recently found out. Heres the rest of the UI if theres anything of note there though.
image

1 Like

the size should be {1,0}{1,0}, this size will take up ur entire screen but just lower the values until its good. something like {0.5,0}{0.5,0} would be good for example.

Have you tried using the FieldofView property in your code to set the zoom level of the GUI and scale it accordingly?

reviving this thread after months… Im coming back to this issue because I never got a answer and I still need this mechanic.

Could you update the videos links as I believe they are both deleted or not accessible?

oh yeah sure, sorry.

External Media

ill edit the OG post too

bumping once again… Still need help

bumping again… still didnt find a solution

still bumping this, please someone help ive been at this for around 2 days or so :sob:

Just a shot in the dark, but if you want it to shrink when you zoom and and grow when you zoom in, would some simple subtraction do the job?

for i = 0, 20 do
	Frame.Transparency = 1 - (i/20) -- 1, 0.95, 0.9, 0.85, ...
	wait(.1)
end

Not really sure why you aren’t using a BillboardGui for this? It does everything you’re looking and also lets you filter out lighting.

BillboardGui Example.rbxm (5.8 KB)

im also using a viewport frame for the player so the character isnt affected by the lighting, and I want the effect to overlap the viewport frame. But Billboard GUIs dont do that