3D2D Hud

Yes, i want something like this: http://forum.facepunch.com/showthread.php?t=1480598
But what i want, is a good way of doing it, beacouse when i try doing it like this:



-- Calculations
local eyePos = EyePos()
local forward = LocalPlayer():GetForward()
-- local forwardAngle = forward:Angle()
local rotation = EyeAngles()

-- 3d2d
cam.Start3D2D( eyePos + (forward * 20), rotation +  Angle(90, 0, -20), 0.2)
	-- Draw stuff here
cam.End3D2D()


It is currently inside a PostDrawOpaqueRenderables hook, but it is not as smooth as i want.

For example, in that post theres a video.
That video shows a HUD that moves very smoothley, but mine does not work smoothly.

Can someone tell me a way to do it as smooth as there please?

Thanks

Unrelated, but you generally want to use PostDrawTranslucentRenderables over PostDrawOpaqueRenderables

Good one, thanks

As for your problem, I am sure it’s just down to “lerping” it properly.

Using this:




	local forward = LocalPlayer():GetAimVector()

Will make it stick to one place properly, from there you can just add more maths to make it move as smooth as you like, depending on movement, etc.

[editline]4th September 2015[/editline]

Actually you want to use this:



	local forward = LocalPlayer():GetEyeTraceNoCursor().Normal


So it’s not attached to the cursor

Testing it now

[editline]3rd September 2015[/editline]

That did the trick! Thanks!
Also, now it goes smooth, but how can i make it so it goes like a bit delayed, so it gets even a nicer effect?

[editline]3rd September 2015[/editline]

I just have another question.
I am tryng to draw text in there, but as i draw it, i saw that the text is not visible, and its behind the panel.
Whats happening?

Le bump

Lerp the 3D2D position

Ups, forgot to mention i already did that, but my question is about the text thing.
So, i draw it, but as i have the lerp set very low, i turn my screen really fast, to see the text is behind that panel.
I draw it as i do with the boxes, and it is vertical.
Its a very weird thing

[editline]4th September 2015[/editline]

Ill post the code now and also a video about what is happening

[editline]4th September 2015[/editline]



local velocity = 1
local aVelocity = 15
local HPColor = Color(192, 57, 43, 255)

local hpLerp = 0
local hpLerp2 = 0
local arLerp = 0

local forwardLerp = LocalPlayer():GetEyeTraceNoCursor().Normal
local angleLerp = LocalPlayer():GetEyeTraceNoCursor().Normal:Angle()

local function HUD3d2dDo()
	-- HP calcs
	local HP = LocalPlayer():Health() or 0
	local Health = math.Clamp(HP, 0, LocalPlayer():GetMaxHealth())

	hpLerp = Lerp(FrameTime() * velocity, hpLerp, Health)
	hpLerp2 = Lerp(FrameTime() * velocity, hpLerp2, HP)
	local FullHealth = math.Round( hpLerp2, 0 )

	local DrawHealth = math.Clamp( math.Min(hpLerp / LocalPlayer():GetMaxHealth(), 1), 0, LocalPlayer():GetMaxHealth())

	-- 3D2D calculations / lerps
	local eyePos = EyePos()
	forwardLerp = LerpVector(FrameTime() * aVelocity, forwardLerp, LocalPlayer():GetEyeTraceNoCursor().Normal) --LocalPlayer():GetForward()
	angleLerp = LerpAngle(FrameTime() * aVelocity, angleLerp, LocalPlayer():GetEyeTraceNoCursor().Normal:Angle()  )

	-- 3d2d
	cam.Start3D2D( eyePos + (forwardLerp * 20), angleLerp + Angle(90, 0, -20), 0.2)
		draw.RoundedBox(0, -40, -80, 20, 40, Color(30, 30, 30, 200))

		draw.RoundedBox(0, 15, -80, 30, 50, Color(30, 30, 30, 200))

		draw.RoundedBox(0, 20, -75, 5, 40, Color(30, 30, 30, 255))
		draw.RoundedBox(0, 21, -74, 3, 38 * DrawHealth, HPColor)

		draw.SimpleText(FullHealth, "3d2dHudText", 24, -54, Color(0, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
		draw.SimpleText(FullHealth, "3d2dHudText", 23, -55, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
	cam.End3D2D()
end
hook.Add("PostDrawTranslucentRenderables", "HUD3d2dPaint", HUD3d2dDo)


There goes the code, now i am with the video

[editline]4th September 2015[/editline]

In the video i set the aVelocity to 1, to be noticable and also i changed it so that the eyePos is static.

[video]https://youtu.be/hf647ZMHnJ0[/video]

Your 3D2D is projected AWAY from you, not TOWARDS you, that’s why you get the text on the other side. Rotate it until it is properly aligned TOWARDS you.

Also, i forgot to mention, that it is like 90º turned, so that it makes me do it so that i change the heigh by the width and so on.
How can i fix that?

[editline]4th September 2015[/editline]

Thanks

Also, don’t use angle+angle for 3d2d, use angle:rotatearoundaxis(axis,degrees)

Ill try it.
Thanks.

[editline]4th September 2015[/editline]

How do i use that function?

I took a look there, but still not understand how to use it.
Also, thank you by all your help, i really do appreciate it.

Just put in random values until you see what it actually does then? Or google “rotate around vector” or something. Or look up how other addons use it?

[editline]4th September 2015[/editline]

A good idea would be putting a math.sin( CurTime() * 50 ) * 90 as the second argument and angle:Up() as the first argument.

Ive got what it does now, thanks