Index: /code/branches/formation/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- /code/branches/formation/src/orxonox/controllers/ArtificialController.cc	(revision 8907)
+++ /code/branches/formation/src/orxonox/controllers/ArtificialController.cc	(revision 8908)
@@ -80,4 +80,5 @@
         this->bShooting_ = false;
         this->bHasTargetPosition_ = false;
+	this->bHasTargetOrientation_=false;
         this->speedCounter_ = 0.2f;
         this->targetPosition_ = Vector3::ZERO;
@@ -372,7 +373,12 @@
             if (distance < 300)
             {
+		 if (bHasTargetOrientation_)
+		    {
+			copyTargetOrientation();
+		    }
                 if (distance < 40)
                 {
                     this->getControllableEntity()->moveFrontBack(0.8f*SPEED_MASTER);
+		   
                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
 
@@ -385,4 +391,5 @@
         {
             this->positionReached();
+	    bHasTargetOrientation_=false;
         }
     }
@@ -391,4 +398,23 @@
     {
         this->moveToPosition(this->targetPosition_);
+    }
+
+    void ArtificialController::copyOrientation(const Quaternion& orient)
+    {
+	//roll angle in radian, difference between master and slave
+	float diff=orient.getRoll().valueRadians()-(this->getControllableEntity()->getOrientation().getRoll().valueRadians());
+	if ((diff<math::twoPi && diff>math::pi) || diff>(math::pi)*3)
+	{
+		diff=diff-math::twoPi;
+	}
+	this->getControllableEntity()->rotateRoll(1.0f*ROTATEFACTOR_MASTER*diff);
+    }
+
+    void ArtificialController::copyTargetOrientation()
+    {
+	if (bHasTargetOrientation_)
+  	{
+		copyOrientation(targetOrientation_);
+	}
     }
 
@@ -476,9 +502,9 @@
         }
     }
-
-    /**
+ /**
         @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
     */
-    void ArtificialController::commandSlaves()
+
+void ArtificialController::commandSlaves()
     {
         if(this->state_ != MASTER) return;
@@ -494,25 +520,26 @@
         }
         else
+	// formation:
         {
             dest += 1.0f*orient*WorldEntity::BACK;
             Vector3 pos = Vector3::ZERO;
+	    bool left=true;
             int i = 1;
-
+	    
             for(std::vector<ArtificialController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
             {
                 pos = Vector3::ZERO;
-                if (i <= 1) pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::LEFT);
-                if (i == 2) pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
-                if (i == 3) pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::UP);
-                if (i >= 4)
-                {
-                    pos += dest  + (float)FORMATION_WIDTH*(orient*WorldEntity::DOWN);
-                    i = 1;
-                    dest += (float)FORMATION_LENGTH*(orient*WorldEntity::BACK);
-                    (*it)->setTargetPosition(pos);
-                    continue;
-                }
-                i++;
+		if (left)
+		{
+                    pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::LEFT);
+		} else
+		{
+		    pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
+		    i++;
+		    dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
+		}		
+		(*it)->setTargetOrientation(orient);
                 (*it)->setTargetPosition(pos);
+		left=!left;
             }
         }
@@ -819,4 +846,16 @@
         this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000));
         this->bHasTargetPosition_ = true;
+    }
+
+    void ArtificialController::setTargetOrientation(const Quaternion& orient)
+    {
+	this->targetOrientation_=orient;	
+	this->bHasTargetOrientation_=true;
+    }
+
+    void ArtificialController::setTargetOrientation(Pawn* target)
+    {
+	if (target)
+	    setTargetOrientation(target->getOrientation());
     }
 
Index: /code/branches/formation/src/orxonox/controllers/ArtificialController.h
===================================================================
--- /code/branches/formation/src/orxonox/controllers/ArtificialController.h	(revision 8907)
+++ /code/branches/formation/src/orxonox/controllers/ArtificialController.h	(revision 8908)
@@ -96,4 +96,6 @@
             void moveToPosition(const Vector3& target);
             void moveToTargetPosition();
+	    void copyOrientation(const Quaternion& orient);
+	    void copyTargetOrientation();
 
             virtual void positionReached() {}
@@ -124,4 +126,7 @@
             void searchRandomTargetPosition();
 
+	    void setTargetOrientation(const Quaternion& orient);
+	    void setTargetOrientation(Pawn* target);
+
             void setTarget(Pawn* target);
             void searchNewTarget();
@@ -138,4 +143,8 @@
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
+
+	    bool bHasTargetOrientation_;
+	    Quaternion targetOrientation_;
+
             WeakPtr<Pawn> target_;
             bool bShooting_;
