Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7093


Ignore:
Timestamp:
Jun 2, 2010, 10:45:14 PM (14 years ago)
Author:
landauf
Message:

Fixed strange movements of the Drone while shooting. Also the drone shoots now every tick instead of every second. It's a real killer-drone!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/orxonox/controllers/DroneController.cc

    r7082 r7093  
    5151        this->owner_ = 0;
    5252        this->drone_ = 0;
     53        this->isShooting_ = false;
    5354
    5455        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this)));
     
    7576        float random;
    7677        float maxrand = 100.0f / ACTION_INTERVAL;
    77         float distanceToTargetSquared;
     78        float distanceToTargetSquared = 0;
    7879
    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         }
     80        if (this->target_)
     81            distanceToTargetSquared = (getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
    8382
    8483        random = rnd(maxrand);
    8584        if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
    8685            this->searchNewTarget();
    87 
    88         if (random < 50 && this->target_ && distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
    89         {
    90             this->isShooting_ = true;
    91             this->aimAtTarget();
    92             drone_->rotateYaw(targetPosition_.x);   //face target
    93             drone_->rotatePitch(targetPosition_.y);
    94             drone_->fire(0);
    95             this->isShooting_ = false;
    96         }
    97 
    9886    }
    9987
     
    10896        if (this->getDrone() && this->getOwner())
    10997        {
     98            if (this->target_)
     99            {
     100                float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
     101                if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
     102                {
     103                    this->isShooting_ = true;
     104                    this->aimAtTarget();
     105                    this->getDrone()->fire(0);
     106                }
     107            }
     108
    110109            float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
    111110            float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
    112             if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared) {
     111            if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared)
     112            {
    113113                this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
    114114            }
    115             else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
     115            else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
     116            {
    116117                this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
    117118            }
    118             else if(!isShooting_) {
     119            else if (!this->isShooting_)
     120            {
    119121                float random = rnd(2.0f);
    120122                float randomSelection = rnd(6.0f);
     
    126128                else if((int)randomSelection==5) drone_->rotateRoll(random);
    127129            }
     130
     131            this->isShooting_ = false;
    128132        }
    129133
Note: See TracChangeset for help on using the changeset viewer.