Index: /code/branches/turretFS14/data/levels/turretTest.oxw
===================================================================
--- /code/branches/turretFS14/data/levels/turretTest.oxw	(revision 10041)
+++ /code/branches/turretFS14/data/levels/turretTest.oxw	(revision 10042)
@@ -34,5 +34,5 @@
 
 
-<SpaceShip position="-100,0,0" yaw=0 pitch=0>
+<!-- <SpaceShip position="-100,0,0" yaw=0 pitch=0>
     <attached>
         <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
@@ -58,7 +58,15 @@
 
     </attached>
-</SpaceShip>
+</SpaceShip> -->
+<StaticEntity position="100,0,0">
+  <attached>
+    <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
 
-<SpaceShip position="100,0,0" yaw=0 pitch=0>
+    <Model mesh="sphere.mesh" position="0,25,0" scale=1.5/>
+
+    <Model mesh="sphere.mesh" position="0,0,30" scale=2/>
+  </attached>
+</StaticEntity>
+<SpaceShip position="100,0,0" yaw=0 pitch=90>
     <attached>
         <Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
@@ -73,13 +81,9 @@
             </templates>
             <controller>
-              <TurretController team=9 />
+              <TurretController team=10 />
             </controller>
         </Turret>
 
-        <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
 
-        <Model mesh="sphere.mesh" position="0,25,0" scale=1/>
-
-        <Model mesh="sphere.mesh" position="0,0,30" scale=1/>
 
     </attached>
Index: /code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- /code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10041)
+++ /code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10042)
@@ -113,8 +113,10 @@
         this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
 
+        //physics don't work when attached :(
+        //this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
 
-        pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
-        yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
-        roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
+        pitch(Degree(localAngularAcceleration_.x()*dt/1000), WorldEntity::World);
+        yaw(Degree(localAngularAcceleration_.y()*dt/1000), WorldEntity::World);
+        roll(Degree(localAngularAcceleration_.z()*dt/1000), WorldEntity::World);
 
         this->localAngularAcceleration_.setValue(0, 0, 0);
Index: /code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- /code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc	(revision 10041)
+++ /code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc	(revision 10042)
@@ -47,5 +47,4 @@
         this->maxYaw_ = 90;
         this->gotOrient_ = false;
-        orxout() << "Constructor " << this << endl;
  	}
 
@@ -95,6 +94,7 @@
  	}
 
- 	bool TurretController::isInRange(Vector3 position)
-    {
+ 	bool TurretController::isInRange(const Vector3 &position)
+    {
+    	//Check distance
         Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
         if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
@@ -103,4 +103,5 @@
         }
 
+        //Check pitch
         Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
         Vector3 dirProjected = dir;
@@ -114,4 +115,5 @@
         }
 
+        //Check yaw
         dirProjected = dir;
         dirProjected.y = 0;
@@ -126,55 +128,77 @@
     }
 
+    void TurretController::aimAtPositionRot(const Vector3 &position)
+    {
+
+        Vector3 currDir = this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT;
+        Vector3 targetDir = position - this->getControllableEntity()->getWorldPosition();
+
+        Quaternion rot = currDir.getRotationTo(targetDir);
+
+        //Don't make the rotation instantaneous
+        rot = Quaternion::Slerp(0.1, Quaternion::IDENTITY, rot);
+
+        this->getControllableEntity()->rotate(rot, WorldEntity::World);
+    }
+    
+
+    void TurretController::aimAtTargetRot()
+    {
+    	this->aimAtPositionRot(this->target_->getWorldPosition());
+    }
+
+    bool TurretController::isLookingAtTargetNew(float angle) const
+    {
+        return (getAngle(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT, this->target_->getWorldPosition()) < angle);
+    }
+
  	void TurretController::tick(float dt)
  	{
-
-
-        if(!gotOrient_)
-        {
-            this->startOrient_ = this->getControllableEntity()->getOrientation();
-            this->localXStart_ = this->startOrient_ * this->localX_;
-            this->localXStart_.normalise();
-            this->localX_ = this->localXStart_;
-            this->localYStart_ = this->startOrient_ * this->localY_;
-            this->localYStart_.normalise();
-            this->localY_ = this->localYStart_;
-            this->localZStart_ = this->startOrient_ * this->localZ_;
-            this->localZStart_.normalise();
-            this->localZ_ = this->localZStart_;
-
-            //startDir should always be (0,0,-1)
-            this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
-
-            this->gotOrient_ = true;
-        }
-
-        //orxout() << "Controller " << this;
-        //orxout() << "\tControllable Entity " << this->getControllableEntity() << endl;
-        WorldEntity* parent = this->getControllableEntity()->getParent();
-        if(parent)
-        {
-            Quaternion parentrot = parent->getOrientation();
-            this->localX_ = parentrot * this->localXStart_;
-            this->localY_ = parentrot * this->localYStart_;
-            this->localZ_ = parentrot * this->localZStart_;
-        }
-
-        orxout() << this->getControllableEntity()->getWorldPosition() << endl;
-
-
-        if (!this->isActive() || !this->getControllableEntity())
-            return;
- 		this->searchTarget();
- 		if(target_)
- 		{
- 			this->aimAtTarget();
- 			//this->getControllableEntity()->lookAt(this->targetPosition_);
- 			//It says move, but really it only turns
- 			this->moveToTargetPosition();
- 			if(this->isLookingAtTarget(Degree(5).valueRadians()))
- 			{
- 				orxout() << 42 << endl;
- 			}
- 		}
+			if(!gotOrient_)
+	        {
+	            this->startOrient_ = this->getControllableEntity()->getOrientation();
+	            this->localXStart_ = this->startOrient_ * this->localX_;
+	            this->localXStart_.normalise();
+	            this->localX_ = this->localXStart_;
+	            this->localYStart_ = this->startOrient_ * this->localY_;
+	            this->localYStart_.normalise();
+	            this->localY_ = this->localYStart_;
+	            this->localZStart_ = this->startOrient_ * this->localZ_;
+	            this->localZStart_.normalise();
+	            this->localZ_ = this->localZStart_;
+
+	            //startDir should always be (0,0,-1)
+	            this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+	            this->gotOrient_ = true;
+
+	        }
+
+	        WorldEntity* parent = this->getControllableEntity()->getParent();
+	        if(parent)
+	        {
+	            Quaternion parentrot = parent->getOrientation();
+	            this->localX_ = parentrot * this->localXStart_;
+	            this->localY_ = parentrot * this->localYStart_;
+	            this->localZ_ = parentrot * this->localZStart_;
+	        }
+
+
+
+	        if (!this->isActive() || !this->getControllableEntity())
+	            return;
+
+	 		this->searchTarget();
+	 		if(target_)
+	 		{
+	 			this->aimAtTarget();
+	 			//this->getControllableEntity()->lookAt(this->targetPosition_);
+	 			//It says move, but really it only turns
+	 			this->aimAtTargetRot();
+	 			if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
+	 			{
+	 				orxout() << 42 << endl;
+	 			}
+	 		}
  	}
  }
Index: /code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
===================================================================
--- /code/branches/turretFS14/src/modules/objects/controllers/TurretController.h	(revision 10041)
+++ /code/branches/turretFS14/src/modules/objects/controllers/TurretController.h	(revision 10042)
@@ -56,6 +56,10 @@
             Vector3 localX_;
             Vector3 localXStart_;
+
+            void aimAtPositionRot(const Vector3 &position);
+            void aimAtTargetRot();
  			void searchTarget();
- 			bool isInRange(Vector3 position);
+ 			bool isInRange(const Vector3 &position);
+ 			bool isLookingAtTargetNew(float angle) const;
  	};
  }
