how did karkat and dave become friends? like, karkat was totally angry and shit & dave was constantly messing with him, but then at the almost-end they're actin all cuddly & sorta being hinted at flushed ?

They spent three years together on a tiny meteor. Post-retcon Rose and Kanaya were busy being gay, Vriska and Terezi were busy being gay, and Gamzee was fuck off doin his own thing, so Dave, Karkat and the Mayor were left to become super best buddies forever (and then some??)