Changeset 10800 for code/branches
- Timestamp:
- Nov 13, 2015, 4:45:44 PM (9 years ago)
- Location:
- code/branches/AI_HS15/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10799 r10800 26 26 * 27 27 */ 28 //bug or feature? Press 4 control keys from {Q,W,E,A,S,D,C} at the same time or 3 keys from {Q,E,A,D}, spaceship goes in free fly mode 28 29 #include "controllers/CommonController.h" 29 30 #include "core/XMLPort.h" … … 45 46 46 47 RegisterClass( CommonController ); 47 float SPEED = 0. 7f/0.02f;48 float ROTATEFACTOR = 0. 3f/0.02f;48 float SPEED = 0.9f/0.02f; 49 float ROTATEFACTOR = 0.5f/0.02f; 49 50 50 51 CommonController::CommonController( Context* context ): Controller( context ) … … 132 133 ) );*/ 133 134 this->setPositionOfTarget( this->target_->getWorldPosition() ); 134 this->setOrientationOfTarget( this->target_->get ControllableEntity() ->getOrientation() );135 this->setOrientationOfTarget( this->target_->getOrientation() ); 135 136 136 137 … … 160 161 if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis ) 161 162 { 162 // if this can make target overshoot163 if ( diffLength < 200 )163 //no way to dodge 164 if ( diffLength < 400 ) 164 165 { 165 166 Vector3* target = new Vector3 ( 0, -200, -200 ); 166 moveToPoint( 167 *target, 168 randomInRange( 45, 180 ) 169 ); 167 this->setTargetPosition( this->positionOfTarget_ ); 168 169 170 170 } 171 171 //do scissors 172 172 else 173 173 { 174 Vector3 target = ( diffUnit )* 150.0f 174 Vector3 target = ( diffUnit )* 150.0f; 175 175 Vector3* randVector = new Vector3( 176 176 randomInRange( -300, 300 ), … … 178 178 randomInRange( -300, 300 ) 179 179 ); 180 Vector3 projection = randVector .dotProduct( diffUnit )* diffUnit;180 Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit; 181 181 *randVector -= projection; 182 target += randVector; 183 moveToPoint( 184 *target, 185 randomInRange( 45, 180 ) 186 ); 182 target += *randVector; 183 this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target ); 184 187 185 } 188 186 } … … 202 200 } 203 201 } 202 else 203 { 204 //if diff is insignificant 205 if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis ) 206 { 207 //no way to dodge 208 if ( diffLength < 400 ) 209 { 210 Vector3* target = new Vector3 ( 0, -200, -200 ); 211 this->setTargetPosition( this->positionOfTarget_ ); 212 213 } 214 //do scissors 215 else 216 { 217 Vector3 target = ( diffUnit )* 150.0f; 218 Vector3* randVector = new Vector3( 219 randomInRange( -300, 300 ), 220 randomInRange( -300, 300 ), 221 randomInRange( -300, 300 ) 222 ); 223 Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit; 224 *randVector -= projection; 225 target += *randVector; 226 this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target ); 227 228 } 229 } 230 //target has advantage 231 else 232 { 233 //if too close 234 if ( diffLength < 300 ) 235 { 236 this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() ); 237 } 238 //move closer 239 else 240 { 241 this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector ); 242 } 243 } 244 } 245 this->bShooting_ = true; 204 246 205 247 } … … 730 772 return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) ); 731 773 else 732 return ( this->getControllableEntity() ->getPosition() .squaredDistance( this-> target_->getPosition()) );774 return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) ); 733 775 } 734 776 … … 738 780 return false; 739 781 740 return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this-> targetPosition_ ) < angle );782 return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT, this->positionOfTarget_ ) < angle ); 741 783 } 742 784 … … 744 786 { 745 787 float squaredDistance = squaredDistanceToTarget(); 788 this->setPositionOfTarget( this->target_->getPosition() ); 789 746 790 if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget( math::pi /( 0.0002f*squaredDistance )) ) 747 791 { … … 760 804 static const float hardcoded_projectile_speed = 750; 761 805 762 this-> targetPosition_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );763 this->bHas TargetPosition_ = ( this->targetPosition_ != Vector3::ZERO );806 this->positionOfTarget_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() ); 807 this->bHasPositionOfTarget_ = ( this->positionOfTarget_ != Vector3::ZERO ); 764 808 765 809 Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() ); … … 767 811 if ( pawn ) 768 812 //pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition() + 4000*( this->getControllableEntity() ->getOrientation() * WorldEntity::FRONT )); 769 pawn->setAimPosition( this-> targetPosition_ );813 pawn->setAimPosition( this->positionOfTarget_ ); 770 814 771 815 this->getControllableEntity() ->fire( 0 ); -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10796 r10800 83 83 static const float hardcoded_projectile_speed = 750; 84 84 85 static const float ACTION_INTERVAL = 1.0f;85 static const float ACTION_INTERVAL = 2.0f; 86 86 87 87 … … 167 167 WeakPtr<ControllableEntity> objectiveTarget_; 168 168 169 169 void maneuver(); 170 170 void chooseManeuverType(); 171 171 void gunsD(); -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10797 r10800 69 69 }*/ 70 70 71 /*if (this->bHasTargetPosition_)72 { 73 this->moveToTargetPosition( );74 } */75 if (executingMoveToPoint_)71 if (this->bHasTargetPosition_) 72 { 73 this->moveToTargetPosition(dt); 74 } 75 /* if (executingMoveToPoint_) 76 76 { 77 77 executingMoveToPoint_ = !this->moveAndRoll(dt); … … 89 89 Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition(); 90 90 float diffLength = diffVector.length(); 91 /*Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);91 Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector); 92 92 Vector3* targetPosition = new Vector3 ( 0, 0, -200 ); 93 Vector3 target = rotationToTarget * (*targetPosition); */93 Vector3 target = rotationToTarget * (*targetPosition); 94 94 if (diffLength > 200) 95 95 this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector); … … 106 106 this->moveAndRoll(dt); 107 107 } 108 } 109 if (this->bShooting_ )108 }*/ 109 if (this->bShooting_ && this->canFire()) 110 110 doFire(); 111 111 SUPER(DivisionController, tick, dt); … … 135 135 }*/ 136 136 //this->chooseManeuverType(); 137 this->maneuver(); 138 137 139 switch (this->maneuverType_) 138 140 {
Note: See TracChangeset
for help on using the changeset viewer.