In recent years , within the development of modern technology , multi agent systems have been noticed . Applications of the multi agent systems can be used in variety of fields such as unmanned aerial vehicle(UAV) , Regulatory and military applications , Air robotics and simulations of natural resources . However these systems suffer from Consensus or collective agreement . Consensus concerns processes by which a collection of interacting agents achieve a common goal . The time period that agents reach a consensus is substantial . Another fascinating and advantageous issue in multi agent systems is the process of achieving a specific formation by the agents which can be time invariant or time varing process . In some cases , not only the agents should maintain their specific formation , but also they should travel on a designated trajectory . One of the most challenging issues in agents formation is that they achieve the consensus and maintain it while there are obstacles in the ambient . Applications of these scenarios are very practical in issues such as imaging or searching and monitoring ambient . In this research , multi agent system is modeled by an Integrator first-order system with linear dynamics and the aforementioned Control law can guarantee that there will be no collisions between the obstacles and the agents in the ambient . Both time invariant and time varing formations are analyzed and an algorithm is proposed that makes the agents track the intended trajectory without any collision between the obstacles and the agents . Simulation results show that the proposed method can achieve and maintain consensus by the agents in an ambient with obstacles . Key Words 1- multi agent systems, 2- unmanned aerial vehicle, 3- consensus, 4- formation, 5- trajectory tracking, 6- obstacle avoidance