We propose a dynamic model for a system consisting of self-propelled agents in which the influence of an agent on another agent is weighted by geographical distance. A parameter $alpha$ is introduced to adjust the influence: the smaller value of $alpha$ means that the closer neighbors have stronger influence on the moving direction. We find that there exists an optimal value of $alpha$, leading to the highest degree of direction consensus. The value of optimal $alpha$ increases as the system size increases, while it decreases as the absolute velocity, the sensing radius and the noise amplitude increase.