Nowadays, with the development of robotics-related technology, its applications permeate many aspects of work and life; In product manufacturing and assembly, tech companies switch from manual to robot automation which improves the production volume and reduces the assembly time. In the tertiary sector including health and social work, the robots learn how to interact with people to meet specified requirements. Path planning constitutes a critical module of robotics engineering that aims to provide the optimal solution for the robot to reach its target point. The artificial potential field methods, refers to APF, are widely used to realize path planning due to their simplicity of calculation and effectiveness in obstacle avoidance. However, the traditional artificial potential field method features the local minimum and oscillation, and unreachable target point problems that make it hard for robots to reach the target point. Based on the weaknesses, an improved version of the gravitation and repulsion force function was introduced in this paper. In addition, the concept of safety distance also contributed to the path planning for robots. Through the simulation experiment, it was shown that the improved APF algorithm successfully addressed the local minima and unreachable target point problem, which could navigate robots to arrive at the destination in both 2D and 3D space by avoiding collision with obstacles.