The main target of this research is to assist the elderly people to walk on different road conditions independently. A method that can transform the walking motion of a walking assistive device between level walking and stair climbing automatically was proposed. To teach the target user how to walk correctly, we defined a trajectory that belongs to healthy people to help the user exercise. Stairs are common in various indoor situations and become a huge challenge for people with gait disorders. To extend the range of physical activity, walking trajectories in different surroundings were imported on the assistive device. Ultrasonic sensors were utilized to detect the distance between stairs and the swing foot. Based on the measured distance, the gait was modified according to a predefined safety distance that was determined experimentally. We also designed trajectory combination methods for changing the device motion patterns between ascending and descending stairs as the walking conditions change. The effectiveness of the system was tested through simulation. The results showed that the device smoothly shifted gait with the proposed methods in this paper. This method has the potential to solve the adaptability of various walking devices to different surroundings.