- Timestamp:
- Apr 12, 2011, 9:41:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/DroneController.cc
r7284 r8238 103 103 this->isShooting_ = true; 104 104 this->aimAtTarget(); 105 this->getDrone()->fire(0); 105 if(!this->friendlyFire()) 106 this->getDrone()->fire(0); 106 107 } 107 108 } … … 147 148 this->destroy(); 148 149 } 150 151 bool DroneController::friendlyFire() 152 { ControllableEntity* droneEntity_ = this->getControllableEntity(); 153 if (!droneEntity_) return false; 154 if(!owner_) return false; 155 if(this->bHasTargetPosition_) 156 { 157 Vector3 ownerPosition_ = owner_->getPosition(); 158 Vector3 toOwner_ = owner_->getPosition() - droneEntity_->getPosition(); 159 Vector3 toTarget_ = targetPosition_ - droneEntity_->getPosition(); 160 if(toTarget_.length() < toOwner_.length()) return false; //owner is far away = in safty 161 float angleToOwner = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, ownerPosition_); 162 float angleToTarget = getAngle(droneEntity_->getPosition(), droneEntity_->getOrientation() * WorldEntity::FRONT, targetPosition_); 163 float angle = angleToOwner - angleToTarget;//angle between target and owner, observed by the drone 164 if(std::sin(angle)*toOwner_.length() < 5.0f)//calculate owner's distance to shooting line 165 return true; 166 } 167 return false;//Default return value: Usually there is no friendlyFire 168 } 149 169 }
Note: See TracChangeset
for help on using the changeset viewer.