Cam.Start3D drawn elements bouncing

Hello,
I’m using a cam.Start3D and cam.Start3D2D. I’ve got it to work how I want, although I’m having issues with the drawn items bouncing whenever a player encounters a step or a fall or damage( tested explosive). I’ve tried correcting it with GetViewPunchAngles, but that doesnt seem to affect anything, nor does it return a useful value when a player step happens. The Start3D is constructed without any arguments, while the Start3D2D is constructed from EyePos and EyeAngles. So overall I’m not really sure if it’s EyePos/Angles or ViewPunches, or both that are causing the issue.

I’d appreciate any help or suggestions, Thanks!

And here’s the code I’ve written if anyone wants to test it out first hand (go run up some stairs):


local screenx = ScrW()
local screeny = ScrH()
local screenmin
if(screenx>=screeny) then
    screenmin=screeny
else
    screenmin=screenx
end

hook.Add("HUDPaint","MyHUDTest",function()
    local player = LocalPlayer()
    local eyepos = player:EyePos()
    local eyeangles = player:EyeAngles()
    cam.Start3D()
    cam.Start3D2D( eyepos + eyeangles:Forward()*(math.sqrt(screenx*screeny)/2) + eyeangles:Right()*-(screenx/2) + eyeangles:Up()*(screeny/2), eyeangles + Angle(90,0,0), 1 )
        surface.SetDrawColor( Color( 255, 165, 0, 255 ) )
        surface.DrawRect( 0, 0, 10, 10 )
        surface.SetDrawColor(Color(255,0,0,255))
        surface.DrawRect(10,10,10,10)
    cam.End3D2D()
    cam.End3D()

    surface.SetDrawColor( Color( 255, 165, 0, 255 ) )
        surface.DrawRect( 20, 20, 10, 10 )
        surface.SetDrawColor(Color(255,0,0,255))
        surface.DrawRect(30,30,10,10)
end)

Sorry for posting something that won’t help you, but do you happen to have a version of that 3D2D code that isn’t on an angle? I tested the one you posted and it seems to be turned to the right 90 degrees

Also, try using

EyePos and

EyeAngles instead of ply:EyePos() and ply:EyeAngles() (they seem to reduce the scale of the jittering)

I don’t think you should be doing a cam.Start3D2D inside of a Start3D. Can’t you use the Start3D2D by itself?

Not in a HUDPaint hook - it even says that on the wiki

MPan1 thanks a lot!! Using the global EyePos and EyeAngles solved it! Makes sense to do that on the client…ugh. I wonder what the exact differences are and if this is just caused by the lag of refrencing LocalPlayer for the pos/angles.hmm.

Also thanks for pointing out the rotation by 90 deg. I shouldn’t use a square to figure out if im oriented properly lol, I’ve made the modification below and now the objects are oriented properly for the screen x/y directions. Thanks!


cam.Start3D2D( eyepos + eyeangles:Forward()*(math.sqrt(screenx*screeny)/2) + eyeangles:Right()*-(screenx/2) + eyeangles:Up()*(screeny/2) , Angle(0,eyeangles.y-90,-eyeangles.p + 90), 1 )


Btw I worked my code from example below if your interested. I’m working on implementing hud elements that transition smoothly from 3d world to player screen…

https://wiki.garrysmod.com/page/cam/Start3D2D