Index: code/branches/newlevel2012/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/newlevel2012/src/orxonox/controllers/FormationController.cc	(revision 9181)
+++ code/branches/newlevel2012/src/orxonox/controllers/FormationController.cc	(revision 9188)
@@ -272,7 +272,13 @@
         }
 
-        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
         float distance = (target - this->getControllableEntity()->getPosition()).length();
-
+		if(coord.x < 0.0001 && coord.y < 0.0001)
+		{
+			// if the ship reaches a direction very close to the direct one, set it to the direct one
+			Vector3 v_temp = this->getControllableEntity()->getPosition();
+			Quaternion quat = v_temp.getRotationTo(target);
+			this->getControllableEntity()->rotate(quat);
+		}
 
         if(this->state_ == FREE)
@@ -281,9 +287,9 @@
             {
                 // Multiply with ROTATEFACTOR_FREE to make them a bit slower
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
-            }
-
-            if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * coord.x * 2);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * coord.y * 2);
+            }
+
+            if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
             {
               this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
@@ -297,6 +303,6 @@
             if (this->target_ || distance > 10)
             {
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * coord.x * 2);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * coord.y * 2);
             }
 
@@ -310,25 +316,25 @@
 
         if(this->state_ == SLAVE)
-        {
-
-           this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
-           this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
-
-            if (distance < 300)
-            {
-		 if (bHasTargetOrientation_)
-		    {
-			copyTargetOrientation();
-		    }
-                if (distance < 100)
-                {   //linear speed reduction
-                    this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
-		   
-                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
-
-            } else {
-                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
-            }
-        }
+		{
+
+			this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * coord.x * 2);
+			this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * coord.y * 2);
+
+			if (distance < 300)
+			{
+				if (bHasTargetOrientation_)
+				{
+					copyTargetOrientation();
+				}
+				if (distance < 100)
+				{ //linear speed reduction
+					this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
+
+				} else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
+
+			} else {
+				this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
+			}
+		}
 
         if (distance < 10)
@@ -383,5 +389,5 @@
     void FormationController::searchNewMaster()
     {
-        if (this->state_==SLAVE) 
+        if (this->state_==SLAVE)
            return;
         if (!this->getControllableEntity())
@@ -394,5 +400,5 @@
         for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
         {
-           
+
             //same team?
             Gametype* gt=this->getGametype();
@@ -479,5 +485,5 @@
 	         bool left=true;
             int i = 1;
-	    
+
             for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
             {
@@ -490,5 +496,5 @@
                     i++;
                     dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
-                }		
+                }
                 (*it)->setTargetOrientation(orient);
                 (*it)->setTargetPosition(pos);
@@ -599,10 +605,10 @@
 
         if (this->state_==SLAVE)  //become master of this formation
-        {   
+        {
             this->slaves_=this->myMaster_->slaves_;
             this->myMaster_->slaves_.clear();
             this->myMaster_->state_=SLAVE;
             this->myMaster_->myMaster_=this;
-            
+
             //delete myself in slavelist
             std::vector<FormationController*>::iterator it2 = std::find(this->slaves_.begin(), this->slaves_.end(), this);
@@ -647,5 +653,5 @@
            if (i>=slaves_.size()/2) break; //half the formation should attack.
        }
-    }     
+    }
 
 
@@ -860,5 +866,5 @@
     void FormationController::setTargetOrientation(const Quaternion& orient)
     {
-        this->targetOrientation_=orient;	
+        this->targetOrientation_=orient;
         this->bHasTargetOrientation_=true;
     }
