[Orxonox-commit 4665] r9336 - code/branches/presentation2012merge/src/orxonox/controllers

landauf at orxonox.net landauf at orxonox.net
Sun Jul 29 22:44:12 CEST 2012


Author: landauf
Date: 2012-07-29 22:44:11 +0200 (Sun, 29 Jul 2012)
New Revision: 9336

Modified:
   code/branches/presentation2012merge/src/orxonox/controllers/FormationController.cc
Log:
fixed weird AI movement introduced in waypoints branch

Modified: code/branches/presentation2012merge/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/presentation2012merge/src/orxonox/controllers/FormationController.cc	2012-07-22 20:44:22 UTC (rev 9335)
+++ code/branches/presentation2012merge/src/orxonox/controllers/FormationController.cc	2012-07-29 20:44:11 UTC (rev 9336)
@@ -281,21 +281,16 @@
 
         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);
-        }
+        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
+        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
 
         if(this->state_ == FREE)
         {
             if (this->target_ || distance > 10)
             {
                 // Multiply with ROTATEFACTOR_FREE to make them a bit slower
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * coord.x * 2);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * coord.y * 2);
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * rotateX);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * rotateY);
             }
 
             if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
@@ -310,8 +305,8 @@
         {
             if (this->target_ || distance > 10)
             {
-                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * coord.x * 2);
-                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * coord.y * 2);
+                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * rotateX);
+                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * rotateY);
             }
 
             if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
@@ -325,8 +320,8 @@
         if(this->state_ == SLAVE)
         {
 
-            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * coord.x * 2);
-            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * coord.y * 2);
+            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * rotateX);
+            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * rotateY);
 
             if (distance < 300)
             {




More information about the Orxonox-commit mailing list