Scaling Text Based on Distance

Hey dudes.
function DrawName( ply )

local pos = ply:EyePos();
pos.z = pos.z + 15

local ang = ply:EyeAngles();
local dist = LocalPlayer():GetPos():Distance( ply:GetPos() );

cam.Start3D2D( pos, EyeAngles():Right():Angle() + Angle(0,0,90), 0.25 );
	draw.DrawText( "Some Text", "Font_HUDFont", 2, 2, Color( 255, 255, 255, 255 ), TEXT_ALIGN_CENTER )

hook.Add( “PostPlayerDraw”, “DrawName”, DrawName )

This performs as expected, but I’m trying to position the 3d/2d camera closer based on the distance.
So the text is larger when the distance is far, and smaller when it’s near.

I’m terrible at math, can anybody provide any insight?

not super familuar with this but if I’m not mistaken you can define the font and do something along the lines of timing or adding to the font size by (dist * .10) and as the distance grows so should the font… it would take some tweaking though

I believe when the font is created, you can’t adjust the size I’m afraid.
As far as I’m aware at least.

Yeah I don’t think you can change font size, but you could change the scale of the 3d2d (the last argument) to some fraction of the distance.

Easy, as the post above me said, see the .25 in your cam.Start3D2D, that’s the scale of the rendering. You can try playing with that, lowering it as distance increases. Though I don’t understand, if the text is drawn in 3d space it should naturally get smaller the further you are from it :v:

You’re also calling EyeAngles() without the player entity… is it a global that assumes localplayer or…?

You can’t scale the actual font but you can scale the 3d2d cam, try playing around with the third argument in cam.Start3D2D.

Yes, you can call it globally. As you and ollie said, I did manage to get the scaling to work. It’s just a tad blurry.

You don’t actually need to scale anything with 3D2D, you know if the player is far enough it will be smaller because that’s how 3D works. Additionally you can fade in/out the text depending on the distance.