- Timestamp:
- Apr 10, 2014, 4:06:03 PM (11 years ago)
- Location:
- code/branches/turretFS14/src/modules/objects/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
r10018 r10031 27 27 */ 28 28 29 #include "TurretController.h" 29 #include "TurretController.h" 30 #include "worldentities/pawns/Pawn.h" 31 #include "Turret.h" 30 32 31 33 namespace orxonox … … 36 38 { 37 39 RegisterObject(TurretController); 38 counter = 0;39 flag = false;40 40 } 41 41 … … 45 45 } 46 46 47 void TurretController::searchTarget() 48 { 49 Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity()); 50 if(target_ && turret->isInRange(target_->getPosition())) 51 { 52 return; 53 } 54 else 55 { 56 this->forgetTarget(); 57 } 58 59 60 ControllableEntity* parent = orxonox_cast<ControllableEntity*>(turret->getParent()); 61 if(parent) 62 { 63 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); 64 if(parenttarget && turret->isInRange(parenttarget->getPosition())) 65 { 66 this->setTarget(parenttarget); 67 turret->setTarget(parenttarget); 68 return; 69 } 70 } 71 72 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 73 { 74 Pawn* entity = orxonox_cast<Pawn*>(*it); 75 if (ArtificialController::sameTeam(this->getControllableEntity(), entity, this->getGametype())) 76 continue; 77 78 if(turret->isInRange(entity->getPosition())) 79 { 80 this->setTarget(entity); 81 turret->setTarget(entity); 82 break; 83 } 84 } 85 } 86 47 87 void TurretController::tick(float dt) 48 88 { 49 counter += dt; 50 if(counter >= 10) 89 if (!this->isActive() || !this->getControllableEntity()) 90 return; 91 this->searchTarget(); 92 this->getControllableEntity()->rotatePitch(0.2); 93 /*if(target_) 51 94 { 52 counter = 0; 53 flag = !flag; 54 orxout() << "Direction change" << endl; 55 } 56 if(flag) 57 { 58 this->getControllableEntity()->rotatePitch(10*dt); 59 //this->getControllableEntity()->rotateYaw(10*dt); 60 } 61 else 62 { 63 this->getControllableEntity()->rotatePitch(-10*dt); 64 //this->getControllableEntity()->rotateYaw(-10*dt); 65 } 95 this->aimAtTarget(); 96 //It says move, but really it only turns 97 this->moveToTargetPosition(); 98 if(this->isLookingAtTarget(Degree(5).valueRadians())) 99 { 100 orxout() << 42 << endl; 101 } 102 }*/ 66 103 } 67 104 } -
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
r10018 r10031 44 44 45 45 private: 46 float counter; 47 bool flag; 46 void searchTarget(); 48 47 }; 49 48 }
Note: See TracChangeset
for help on using the changeset viewer.