Index: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc	(revision 10039)
@@ -44,13 +44,4 @@
     {
         RegisterObject(Turret);
-        this->startOrient_ = Quaternion::IDENTITY;
-        this->startDir_ = Vector3::ZERO;
-        this->localZ_ = Vector3::UNIT_Z;
-        this->localY_ = Vector3::UNIT_Y;
-        this->localX_ = Vector3::UNIT_X;
-        this->maxPitch_ = 0;
-        this->maxYaw_ = 0;
-        this->attackRadius_ = 200;
-        this->gotOrient_ = false;
         this->rotationThrust_ = 50;
 
@@ -110,40 +101,6 @@
     }
 
-    bool Turret::isInRange(Vector3 position)
-    {
-        Vector3 distance = position - this->getPosition();
-        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
-        {
-            return false;
-        }
-
-        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
-        Vector3 dirProjected = dir;
-        dirProjected.x = 0;
-        Vector3 startDirProjected = this->startDir_;
-        startDirProjected.x = 0;
-        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
-        if(angle > this->maxPitch_)
-        {
-            return false;
-        }
-
-        dirProjected = dir;
-        dirProjected.y = 0;
-        startDirProjected = this->startDir_;
-        startDirProjected.y = 0;
-        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
-        if(angle > this->maxYaw_)
-        {
-            return false;
-        }
-        return true;
-    }
-
     void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
-        XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
-        XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
-        XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
         SUPER(Turret, XMLPort, xmlelement, mode);
     }
@@ -153,24 +110,13 @@
         SUPER(Turret, tick, dt);
 
-        if(!gotOrient_)
-        {
-            this->startOrient_ = this->getOrientation();
-            this->localX_ = this->startOrient_ * this->localX_;
-            this->localX_.normalise();
-            this->localY_ = this->startOrient_ * this->localY_;
-            this->localY_.normalise();
-            this->localZ_ = this->startOrient_ * this->localZ_;
-            this->localZ_.normalise();
+        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
+        this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
 
-            //startDir should always be (0,0,-1)
-            this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
 
-            this->gotOrient_ = true;
-        }
+        pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
+        yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
+        roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
 
-        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
-        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
         this->localAngularAcceleration_.setValue(0, 0, 0);
     }
-
 }
Index: code/branches/turretFS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.h	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/Turret.h	(revision 10039)
@@ -54,35 +54,6 @@
             virtual void tick(float dt);
 
-            virtual bool isInRange(Vector3 position);
-
-            inline void setMaxPitch(Ogre::Real pitch)
-                {this->maxPitch_ = pitch;}
-
-            inline Ogre::Real getMaxPitch()
-                {return this->maxPitch_;}
-
-            inline void setMaxYaw(Ogre::Real yaw)
-                {this->maxYaw_ = yaw;}
-
-            inline Ogre::Real getMaxYaw()
-                {return this->maxYaw_;}
-
-            inline void setAttackRadius(float radius)
-                {this->attackRadius_ = radius;}
-
-            inline float getAttackRadius()
-                {return this->attackRadius_;}
-
 
         private:
-            bool gotOrient_;
-            Ogre::Real maxPitch_;
-            Ogre::Real maxYaw_;
-            float attackRadius_;
-            Quaternion startOrient_;
-            Vector3 startDir_;
-            Vector3 localZ_;
-            Vector3 localY_;
-            Vector3 localX_;
             float rotationThrust_;
 
@@ -92,3 +63,2 @@
 
 #endif
-
Index: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc	(revision 10039)
@@ -38,4 +38,14 @@
  	{
  		RegisterObject(TurretController);
+ 		this->startOrient_ = Quaternion::IDENTITY;
+        this->startDir_ = Vector3::ZERO;
+        this->localZ_ = Vector3::UNIT_Z;
+        this->localY_ = Vector3::UNIT_Y;
+        this->localX_ = Vector3::UNIT_X;
+        this->attackRadius_ = 200;
+        this->maxPitch_ = 90;
+        this->maxYaw_ = 90;
+        this->gotOrient_ = false;
+        orxout() << "Constructor " << this << endl;
  	}
 
@@ -48,5 +58,5 @@
  	{
         Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
-        if(target_ && turret->isInRange(target_->getPosition()))
+        if(target_ && this->isInRange(target_->getWorldPosition()))
         {
         	return;
@@ -62,5 +72,5 @@
         {
         	Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
-        	if(parenttarget && turret->isInRange(parenttarget->getPosition()))
+        	if(parenttarget && this->isInRange(parenttarget->getWorldPosition()))
         	{
         		this->setTarget(parenttarget);
@@ -76,5 +86,5 @@
             	continue;
 
-            if(turret->isInRange(entity->getPosition()))
+            if(this->isInRange(entity->getWorldPosition()))
             {
             	this->setTarget(entity);
@@ -85,13 +95,79 @@
  	}
 
+ 	bool TurretController::isInRange(Vector3 position)
+    {
+        Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
+        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
+        {
+            return false;
+        }
+
+        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
+        Vector3 dirProjected = dir;
+        dirProjected.x = 0;
+        Vector3 startDirProjected = this->startDir_;
+        startDirProjected.x = 0;
+        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxPitch_)
+        {
+            return false;
+        }
+
+        dirProjected = dir;
+        dirProjected.y = 0;
+        startDirProjected = this->startDir_;
+        startDirProjected.y = 0;
+        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+        if(angle > this->maxYaw_)
+        {
+            return false;
+        }
+        return true;
+    }
+
  	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();
- 		this->getControllableEntity()->rotatePitch(0.2);
- 		/*if(target_)
+ 		if(target_)
  		{
  			this->aimAtTarget();
+ 			//this->getControllableEntity()->lookAt(this->targetPosition_);
  			//It says move, but really it only turns
  			this->moveToTargetPosition();
@@ -100,5 +176,5 @@
  				orxout() << 42 << endl;
  			}
- 		}*/
+ 		}
  	}
  }
Index: code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.h	(revision 10031)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.h	(revision 10039)
@@ -44,5 +44,18 @@
 
  		private:
+            bool gotOrient_;
+            float attackRadius_;
+            Ogre::Real maxPitch_;
+            Ogre::Real maxYaw_;
+            Quaternion startOrient_;
+            Vector3 startDir_;
+            Vector3 localZ_;
+            Vector3 localZStart_;
+            Vector3 localY_;
+            Vector3 localYStart_;
+            Vector3 localX_;
+            Vector3 localXStart_;
  			void searchTarget();
+ 			bool isInRange(Vector3 position);
  	};
  }
