Changeset 7093 for code/branches
- Timestamp:
- Jun 2, 2010, 10:45:14 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
r7082 r7093 51 51 this->owner_ = 0; 52 52 this->drone_ = 0; 53 this->isShooting_ = false; 53 54 54 55 this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this))); … … 75 76 float random; 76 77 float maxrand = 100.0f / ACTION_INTERVAL; 77 float distanceToTargetSquared ;78 float distanceToTargetSquared = 0; 78 79 79 if (target_) { 80 const Vector3& locTargetDir = getDrone()->getOrientation().UnitInverse()*((getDrone()->getWorldPosition())-(target_->getWorldPosition())); //Vector from Drone To target out of drones local coordinate system 81 distanceToTargetSquared = locTargetDir.squaredLength(); 82 } 80 if (this->target_) 81 distanceToTargetSquared = (getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength(); 83 82 84 83 random = rnd(maxrand); 85 84 if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange())) 86 85 this->searchNewTarget(); 87 88 if (random < 50 && this->target_ && distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))89 {90 this->isShooting_ = true;91 this->aimAtTarget();92 drone_->rotateYaw(targetPosition_.x); //face target93 drone_->rotatePitch(targetPosition_.y);94 drone_->fire(0);95 this->isShooting_ = false;96 }97 98 86 } 99 87 … … 108 96 if (this->getDrone() && this->getOwner()) 109 97 { 98 if (this->target_) 99 { 100 float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength(); 101 if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange())) 102 { 103 this->isShooting_ = true; 104 this->aimAtTarget(); 105 this->getDrone()->fire(0); 106 } 107 } 108 110 109 float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner(); 111 110 float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner(); 112 if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) { 111 if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) 112 { 113 113 this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner 114 114 } 115 else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) { 115 else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) 116 { 116 117 this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner 117 118 } 118 else if(!isShooting_) { 119 else if (!this->isShooting_) 120 { 119 121 float random = rnd(2.0f); 120 122 float randomSelection = rnd(6.0f); … … 126 128 else if((int)randomSelection==5) drone_->rotateRoll(random); 127 129 } 130 131 this->isShooting_ = false; 128 132 } 129 133
Note: See TracChangeset
for help on using the changeset viewer.