- Timestamp:
- Dec 7, 2015, 8:34:20 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10906 r10923 63 63 void FightingController::lookAtTarget(float dt) 64 64 { 65 if (!this || !this->getControllableEntity()) 66 return; 65 67 ControllableEntity* entity = this->getControllableEntity(); 66 68 if ( !entity ) … … 126 128 float diffLength = diffVector.length(); 127 129 Vector3 diffUnit = diffVector/diffLength; 128 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f) 129 || this->deltaHp < 0; 130 131 if (!this || !this->getControllableEntity()) 132 return; 130 133 131 134 //too far? well, come closer then … … 139 142 } 140 143 else 141 { 144 { 145 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f) 146 || this->deltaHp < 0; 142 147 this->bKeepFormation_ = false; 148 149 if (!this || !this->getControllableEntity()) 150 return; 143 151 // if (this->actionCounter_ % 3 == 0) 144 152 if (maneuverCounter_ <= 1.2) … … 173 181 } 174 182 } 175 /*//too close? How do u expect to dodge anything? Just attack! 176 else if (diffLength < 1000) 177 { 178 this->bKeepFormation_ = false; 179 180 //at this point, just look and shoot 181 if (diffLength < 1000) 182 { 183 this->stopMoving(); 184 this->startLookingAtTarget(); 185 186 } 187 else 188 { 189 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f); 190 } 191 } 192 //Good distance? Check if target looks at us. It doesn't? Go hunt! 193 else if (!bTargetIsLookingAtThis) 194 { 195 this->bKeepFormation_ = false; 196 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f); 197 } 198 //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 199 else 200 { 201 this->bKeepFormation_ = false; 202 if (maneuverCounter_ == 0) 203 { 204 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f); 205 return; 206 } 207 if (this->actionCounter_ % 3 == 0) 208 dodge(thisPosition, diffLength, diffUnit); 209 }*/ 210 } 211 void FightingController::dodgeTowards (Vector3& position) 212 { 213 Vector3 thisPosition = this->getControllableEntity()->getPosition(); 214 Vector3 diff = (position - thisPosition); 215 float diffLength = diff.length(); 216 Vector3 diffUnit = diff/diffLength; 217 float factor = 300.0f; 218 if (diffLength < 300) 219 { 220 this->setTargetPosition(position); 221 return; 222 } 223 else if (diffLength < 600) 224 factor = 400.0f; 225 else if (diffLength < 1000) 226 factor = 700.0f; 227 else 228 factor = 1000.0f; 229 float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 230 float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 231 float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 232 this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor); 233 // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z) << endl; 234 this->boostControl(); 235 } 183 } 184 236 185 void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit) 237 186 { … … 257 206 { 258 207 //no target? why fire? 259 if (!this->target_ )208 if (!this->target_ || !this->getControllableEntity()) 260 209 return false; 261 210 Vector3 newPositionOfTarget = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), … … 274 223 float FightingController::squaredDistanceToTarget() const 275 224 { 276 if (!this ->getControllableEntity())225 if (!this || !this->getControllableEntity()) 277 226 return 0; 278 227 if (!this->target_ || !this->getControllableEntity()) … … 294 243 Pawn* FightingController::closestTarget() const 295 244 { 296 if (!this ->getControllableEntity())245 if (!this || !this->getControllableEntity()) 297 246 return 0; 298 247
Note: See TracChangeset
for help on using the changeset viewer.