This research deals with hierarchical modular structure which is noted as the assembly method in view of the recent upsizing of space structures. The idea is dividing a large space structure into multiple modules and homogeneous automatic assembly functions are installed on each of a module. Hence the shape and function of the entire structure has diversity as they can be changed by the arrangement of modules, regardless of the size of the structure. The conventional researches of locomotion and docking / release mechanisms installed on each module and keeping such characteristics are limited to two-dimensional. In this research, we propose a mechanism using an electromagnet that can be assembled into any shape in three dimensions. The size and arrangement of the electromagnet are optimized to maximize its movement performance by using the Response Surface Method (RSM) for making response surface and applied downhill simplex method. On that basis, the demonstration experiment was actually carried out and the success rate was compared with the existing method to demonstrate the effectiveness of the proposed method.