The problem of finding the optimal path within a certain range exists in various scenarios in our lives, such as the traveling salesman problem, robot automatic path selection problem, vehicle and pedestrian navigation, game path navigation, communication routing, logistics and transportation planning problems, etc. , through the optimization of path problems, we can help people improve resource utilization, improve work efficiency, reduce production costs, or complete the goal of a specific scenario, etc. Therefore, solving the path optimization problem is a very important task in our reality. In order to improve the game experience of the players in the game, this paper studies how to use the particle swarm optimization method to solve the optimal route of NPC.