This paper presents a motion planning strategy for legged robots using locomotion primitives in the complex 3D environments. First, we define configuration, motion primitives and locomotion primitives for legged robots. A hierarchical motion planning method based on a combination of 2.5 dimensional maps such as an obstacle height map, a passage map, and a gradient map of obstacles to distinguish obstacles. A high-level path planner finds a global path from a 2D navigation map. A mid-level planner creates sub-goals that help the legged robot efficiently cope with various obstacles using only a small set of locomotion primitives that are useful for stable navigation of the robot. A local obstacle map that describes the edge or border of the obstacles is used to find the sub-goals along the global path. A low-level planner searches for a feasible sequence of locomotion primitives between sub-goals. We use heuristic algorithm in local motion planner. The proposed planning method is verified by both locomotion and soccer experiments on a small biped robot in a cluttered environment. Experiment results show an improvement in motion stability.