During locomotion, animals employ visual and mechanical cues in order to establish the orientation of their head, which reflects the orientation of the visual coordinate system. However, in certain situations, contradictory cues may suggest different orientations relative to the environment. We recorded blowflies walking on a horizontal or tilted surface surrounded by visual cues suggesting a variety of orientations. We found that the different orientations relative to gravity of visual cues and walking surface were integrated, with the orientation of the surface being the major contributor to head orientation, while visual cues and gravity also play an important role. In contrast, visual cues did not affect body orientation much. Cue integration was modeled as the weighted sum of orientations suggested by the different cues. Our model suggests that in the case of lacking visual cues, more weight is given to gravity.