Get exponential bullet-drop to reach certain distance

Throw this into a quick SWEP if you would, my man.


    function SWEP:DrawWorldModel()
    
        local Laser = Material( "cable/redlaser" )
    
            local cdTr = util.TraceLine( {
                start = self.Owner:EyePos( ),
                endpos = self.Owner:EyePos( ), 
                mask   = MASK_SHOT,
                filter = self.Owner
                } )

            local i = 0
            local targetLength = math.abs( math.sin( CurTime( ) ) * 512 )

            while !cdTr.Hit do
        
                local blah = cdTr.HitPos

                cdTr = util.TraceLine( {
                    start = cdTr.HitPos,
                    endpos = cdTr.HitPos + Angle( 0, 0, 0 ):Forward( ) * ( ( targetLength / 32 ) ) + Vector( 0, 0, ( i * -1 ) ),
                    mask   = MASK_SHOT,
                    filter = self.Owner
                    } )

                i = i + 1
    
            render.DrawBeam( blah, cdTr.HitPos, 1, 1, 1, Color( 255, 0, 255, 255 ) )

            end
    
        local bulletTr = { ["HitPos"] = cdTr.HitPos, ["HitNormal"]=cdTr.HitNormal, ["Entity"]=cdTr.Entity }
    
        render.DrawBeam( self.Owner:EyePos( ), self.Owner:EyePos( ) + Angle( 0, 0, 0 ):Forward( ) * targetLength, 1, 1, 1, Color( 0, 0, 255, 255 ) )
    
        print( ( ( self.Owner:EyePos( ) + Angle( 0, 0, 0 ):Forward( ) * targetLength ) - bulletTr.HitPos ).x )

        self:DrawModel( )

end

I need the pink line to match the blue line. It’s a simulation of bullet drop, and the way it’s supposed to work is the curved pink line will meet the ground at the same length as the blue line. I have no idea how to do this though.

Ideally, the trace would be broken up into 32 units and check to see if it’s hit something. If it doesn’t, it drops a certain amount and repeat until it hits the ground at the target length away. I’m using a sinewave simply for testing.