Changeset 7082
- Timestamp:
- Jun 2, 2010, 2:26:25 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
r7060 r7082 63 63 void DroneController::setOwner(Pawn* owner){ 64 64 this->owner_ = owner; 65 } 65 } 66 66 67 67 void DroneController::setDrone(Drone* drone) … … 70 70 this->setControllableEntity(drone); 71 71 } 72 72 73 73 void DroneController::action() 74 74 { … … 81 81 distanceToTargetSquared = locTargetDir.squaredLength(); 82 82 } 83 83 84 84 random = rnd(maxrand); 85 85 if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange())) … … 106 106 void DroneController::tick(float dt) 107 107 { 108 float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner(); 109 float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner(); 110 if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) { 111 this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner 108 if (this->getDrone() && this->getOwner()) 109 { 110 float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner(); 111 float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner(); 112 if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) { 113 this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner 114 } 115 else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) { 116 this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner 117 } 118 else if(!isShooting_) { 119 float random = rnd(2.0f); 120 float randomSelection = rnd(6.0f); 121 if((int)randomSelection==0) drone_->moveUpDown(random); 122 else if((int)randomSelection==1) drone_->moveRightLeft(random); 123 else if((int)randomSelection==2) drone_->moveFrontBack(random); 124 else if((int)randomSelection==3) drone_->rotateYaw(random); 125 else if((int)randomSelection==4) drone_->rotatePitch(random); 126 else if((int)randomSelection==5) drone_->rotateRoll(random); 127 } 112 128 } 113 else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) { 114 this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner 115 } 116 else if(!isShooting_) { 117 float random = rnd(2.0f); 118 float randomSelection = rnd(6.0f); 119 if((int)randomSelection==0) drone_->moveUpDown(random); 120 else if((int)randomSelection==1) drone_->moveRightLeft(random); 121 else if((int)randomSelection==2) drone_->moveFrontBack(random); 122 else if((int)randomSelection==3) drone_->rotateYaw(random); 123 else if((int)randomSelection==4) drone_->rotatePitch(random); 124 else if((int)randomSelection==5) drone_->rotateRoll(random); 125 } 126 129 127 130 SUPER(AIController, tick, dt); 128 131
Note: See TracChangeset
for help on using the changeset viewer.