Changeset 7060 for code/branches/presentation3/src/orxonox/controllers
- Timestamp:
- May 31, 2010, 4:44:02 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
r7038 r7060 75 75 float random; 76 76 float maxrand = 100.0f / ACTION_INTERVAL; 77 float distanceToTargetSquared; 77 78 78 // const Vector3& ownerPosition = getOwner()->getWorldPosition();79 // const Vector3& dronePosition = getDrone()->getWorldPosition();80 81 // const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(ownerPosition-dronePosition); //Vector from Drone To Owner out of drones local coordinate system82 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 } 83 83 84 random = rnd(maxrand); 84 if ( random < 30 && (!this->target_))85 if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange())) 85 86 this->searchNewTarget(); 86 87 87 if (random < 50 && this->target_ )88 if (random < 50 && this->target_ && distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange())) 88 89 { 89 90 this->isShooting_ = true; … … 105 106 void DroneController::tick(float dt) 106 107 { 107 // Drone *myDrone = static_cast<Drone*>(this->getControllableEntity());108 108 float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner(); 109 109 float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner(); 110 110 if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) { 111 this->moveToPosition(this->getOwner()->getWorldPosition()); 111 this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner 112 112 } 113 113 else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) { 114 this->moveToPosition(-this->getOwner()->getWorldPosition()); 114 this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner 115 115 } 116 116 else if(!isShooting_) { … … 131 131 void DroneController::ownerDied() 132 132 { 133 // if (this->target_) { //Drone has some kind of Stockholm-Syndrom --> gets attached to Owners Killer 134 // this->setOwner(target_); 135 // this->searchNewTarget(); 136 // } 133 137 if (this->drone_) 134 138 this->drone_->destroy();
Note: See TracChangeset
for help on using the changeset viewer.