When the Rebels were forced to flee Yavin for the ice planet Hoth, R2-D2 and C-3PO naturally came along. The environment outside was too cold for droids like them to function, but R2 did scan for signals when Luke and Han were missing, and C-3PO calculated the odds of their survival, which nobody wanted to hear. When Imperial forces arrived and the Hoth base had to be abandoned, C-3PO left with Han and Leia on the Millennium Falcon, while R2-D2 left with Luke in his X-Wing.
C-3PO was mostly an annoyance as the crew of the Falcon had to hide from the Empire and navigate an asteroid field. When they arrived in Cloud City on the planet Bespin, 3PO wondered away from his friends after encountering another protocol droid. He thought he heard an R2 unit and was looking for another familiar face, but instead he encountered a squad of Imperial stormtroopers and was literally blasted to pieces. Fortunately, those pieces were found by Chewbacca, the tech-savvy Wookiee copilot of the Millennium Falcon, who was able to restore 3PO to consciousness but didn't have a chance to fully reassemble him.
Meanwhile, R2-D2 went with Luke Skywalker to the swamp planet Dagobah, where Luke was to train with the Jedi Master Yoda. A swamp is a bad place for an astromech droid, and R2 quickly found himself submerged in sludge and even swallowed whole by a giant reptile, but fortunately it found him indigestible and spit him out. R2's only role in Luke's Jedi training was as a weight to be lifted with the Force, and he spent a lot of time sitting around waiting in this uncomfortable environment. Eventually, Luke had a vision of his friends in peril on Bespin, and he and R2 left to save them. There R2 and the disassembled C-3PO were reunited once again, and as they escaped on the Falcon, R2 helped put his friend back together. Unfortunately, Han Solo had been captured on Bespin and taken to the gangster known as Jabba the Hutt.