- Timestamp:
- Nov 30, 2015, 9:34:54 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc
r10903 r10906 118 118 if ( !this->target_ || !this->getControllableEntity()) 119 119 return; 120 maneuverCounter_++; 121 if (maneuverCounter_ > 5) 122 maneuverCounter_ = 0; 120 123 121 124 122 Vector3 thisPosition = this->getControllableEntity()->getWorldPosition(); … … 128 126 float diffLength = diffVector.length(); 129 127 Vector3 diffUnit = diffVector/diffLength; 130 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/1 5.0f)128 bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f) 131 129 || this->deltaHp < 0; 132 130 … … 140 138 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f); 141 139 } 142 //too close? How do u expect to dodge anything? Just attack! 140 else 141 { 142 this->bKeepFormation_ = false; 143 // if (this->actionCounter_ % 3 == 0) 144 if (maneuverCounter_ <= 1.2) 145 { 146 // orxout(internal_error) << "attacking" << endl; 147 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 50.0f); 148 return; 149 } 150 else if (bTargetIsLookingAtThis || diffLength < 700.0f) 151 { 152 // orxout(internal_error) << "dodging" << endl; 153 if (!this->bStartedDodging_) 154 { 155 this->bStartedDodging_ = true; 156 dodge(thisPosition, diffLength, diffUnit); 157 } 158 } 159 else 160 { 161 if (diffLength < 1000) 162 { 163 // orxout(internal_error) << "looking" << endl; 164 this->stopMoving(); 165 this->startLookingAtTarget(); 166 167 } 168 else 169 { 170 // orxout(internal_error) << "closing up" << endl; 171 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f); 172 } 173 } 174 } 175 /*//too close? How do u expect to dodge anything? Just attack! 143 176 else if (diffLength < 1000) 144 177 { … … 146 179 147 180 //at this point, just look and shoot 148 if (diffLength < 500)181 if (diffLength < 1000) 149 182 { 150 183 this->stopMoving(); 151 184 this->startLookingAtTarget(); 185 152 186 } 153 187 else … … 160 194 { 161 195 this->bKeepFormation_ = false; 162 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f);196 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f); 163 197 } 164 198 //That's unfortunate, he is looking and probably shooting... try to dodge what we can... … … 168 202 if (maneuverCounter_ == 0) 169 203 { 170 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);204 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f); 171 205 return; 172 206 } 173 207 if (this->actionCounter_ % 3 == 0) 174 dodge(thisPosition, diff Unit);175 } 208 dodge(thisPosition, diffLength, diffUnit); 209 }*/ 176 210 } 177 211 void FightingController::dodgeTowards (Vector3& position) … … 200 234 this->boostControl(); 201 235 } 202 void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit)236 void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit) 203 237 { 204 238 //d.x*x + d.y*y + d.z*z == 0 205 239 //z = 1/d.z * (-d.y*y - d.x * x) 206 float x = CommonController::randomInRange ( 100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);207 float y = CommonController::randomInRange ( 100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);240 float x = CommonController::randomInRange (300, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 241 float y = CommonController::randomInRange (300, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1); 208 242 float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y); 209 this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f)); 243 if (diffLength < 150.0f) 244 { 245 this->setTargetPosition(this->positionOfTarget_ + Vector3(z,x,y)); 246 } 247 else 248 { 249 this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : 250 (diffLength < 700.0f ? -diffUnit*700.0f : diffUnit * 50.0f))); 251 252 } 210 253 this->boostControl(); 211 254 … … 225 268 } 226 269 227 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 20.0f);270 return squaredDistanceToTarget() < this->attackRange_*this->attackRange_ && this->isLookingAtTarget(math::pi / 10.0f); 228 271 } 229 272
Note: See TracChangeset
for help on using the changeset viewer.