This paper deals with collision avoidance problems while following an optimal trajectory for a group of agents operating in open space. The basic idea is to use the Model Predictive Control (MPC) technique to solve a realtime optimization problem with non-convex constraints over a finite time horizon. Both centralized and decentralized MPC formulations are presented. In a second stage it is shown that velocity constraints can be added to the collision avoidance restrictions in the optimization problem. Following a specified trajectory, the agents move in the same direction and end up eventually in a particular formation. A primer ingredient in the control design is the generation of a flat trajectory, planned in the physical open space. This allows the agents to maneuver successfully in a dynamic environment and to reach a common objective.