Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 30, 2015, 9:34:54 PM (9 years ago)
Author:
gania
Message:

tried to fix fighting whn fps is low

Location:
code/branches/campaignHS15/src/orxonox/controllers
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10903 r10906  
    5353        this->squaredaccuracy_ = 2500;
    5454        this->bFirstTick_ = true;
    55 
     55        this->bStartedDodging_ = false;
     56        this->timeDodged_ = 0;
    5657        RegisterObject(ActionpointController);
    5758
     
    7879            this->timeout_ -= dt;
    7980        }
     81        if (this->bStartedDodging_)
     82        {
     83            this->timeDodged_ += dt;
     84            if (this->timeDodged_ > 2.0f)
     85            {
     86                this->bStartedDodging_ = false;
     87                this->timeDodged_ = 0;
     88            }
     89        }
     90        maneuverCounter_ += dt;
     91        if (maneuverCounter_ > 6.0f)
     92            maneuverCounter_ = 0;
    8093        if (timeout_ <= 0)
    8194            this->bFiredRocket_ = false;
     
    110123            this->bFirstTick_ = false;
    111124        }
    112 
     125        if (this->hasTarget())
     126        {
     127            this->maneuver();
     128            if (static_cast<int>(this->maneuverCounter_*100) % 3 == 0)
     129                this->bShooting_ = this->canFire();
     130        }
    113131        SUPER(ActionpointController, tick, dt);
    114132    }
     
    123141        this->deltaHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth() - this->previousHp;
    124142        this->previousHp = orxonox_cast<Pawn*> (this->getControllableEntity())->getHealth();
     143
    125144        // if (this->actionCounter_ % 2 == 0)
    126145        //No action -> pop one from stack
     
    236255            }
    237256        }
    238         if (this->hasTarget())
    239         {
    240             this->maneuver();
    241             this->bShooting_ = this->canFire();
     257
    242258            // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
    243259            // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
     
    252268            // //----fire if you can----
    253269            // this->bShooting_ = this->canFire(); 
    254         }
     270         
    255271        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    256272
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.cc

    r10903 r10906  
    118118        if ( !this->target_ || !this->getControllableEntity())
    119119            return;
    120         maneuverCounter_++;
    121         if (maneuverCounter_ > 5)
    122             maneuverCounter_ = 0;
     120
    123121
    124122        Vector3 thisPosition = this->getControllableEntity()->getWorldPosition();
     
    128126        float diffLength = diffVector.length();
    129127        Vector3 diffUnit = diffVector/diffLength;
    130         bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/15.0f)
     128        bool bTargetIsLookingAtThis = CommonController::isLooking (this->target_, this->getControllableEntity(), math::pi/10.0f)
    131129            || this->deltaHp < 0;
    132130
     
    140138            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);
    141139        }
    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!
    143176        else if (diffLength < 1000)
    144177        {   
     
    146179
    147180            //at this point, just look and shoot
    148             if (diffLength < 500)
     181            if (diffLength < 1000)
    149182            {
    150183                this->stopMoving();
    151184                this->startLookingAtTarget();
     185
    152186            }
    153187            else
     
    160194        {
    161195            this->bKeepFormation_ = false;
    162             this->setTargetPosition(this->positionOfTarget_ - diffUnit * 300.0f);
     196            this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);
    163197        }
    164198        //That's unfortunate, he is looking and probably shooting... try to dodge what we can... 
     
    168202            if (maneuverCounter_ == 0)
    169203            {
    170                 this->setTargetPosition(this->positionOfTarget_ - diffUnit * 100.0f);   
     204                this->setTargetPosition(this->positionOfTarget_ - diffUnit * 900.0f);   
    171205                return;
    172206            }
    173207            if (this->actionCounter_ % 3 == 0)
    174                 dodge(thisPosition, diffUnit);
    175         }
     208                dodge(thisPosition, diffLength, diffUnit);
     209        }*/
    176210    }
    177211    void FightingController::dodgeTowards (Vector3& position)
     
    200234        this->boostControl();
    201235    }
    202     void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit)
     236    void FightingController::dodge(const Vector3& thisPosition, float diffLength, Vector3& diffUnit)
    203237    {
    204238        //d.x*x + d.y*y + d.z*z == 0
    205239        //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);
    208242        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        }
    210253        this->boostControl();
    211254
     
    225268        }
    226269
    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);
    228271    }
    229272
  • code/branches/campaignHS15/src/orxonox/controllers/FightingController.h

    r10898 r10906  
    6767            void maneuver(); //<! sets this->targetPosition_, which is a Vector3 of where this ship flies. Decision is made based on
    6868                             //<! the distance to enemy, if being attacked, dodge() is called, otherwise ship just flies towards this->target_.
    69             void dodge(const Vector3& thisPosition, Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between
     69            void dodge(const Vector3& thisPosition, float diffLength,  Vector3& diffUnit); //<! choose a random Vector3 perpendicular to the difference vector between
    7070                                                                        //<! this and target_ plus or minus some amount in difference vector direction,
    7171                                                                        //<! depending on whether it is better to close up or survive.
     
    8484            int attackRange_;
    8585            bool bShooting_;
    86             int maneuverCounter_;   
     86            float maneuverCounter_;   
    8787            bool bLookAtTarget_;
    8888            float deltaHp;
    8989            float previousHp;
     90            bool bStartedDodging_;
     91            float timeDodged_;
    9092            //WEAPONSYSTEM DATA
    9193            int rocketsLeft_;
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10888 r10906  
    125125                if (this->hasTarget())
    126126                {
    127                     this->maneuver();
    128                     this->bShooting_ = this->canFire();
     127                    // this->maneuver();
     128                    // this->bShooting_ = this->canFire();
    129129                    // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
    130130                    // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10888 r10906  
    112112                if (this->hasTarget())
    113113                {
    114                     this->maneuver();
    115                     this->bShooting_ = this->canFire();
     114                    // this->maneuver();
     115                    // this->bShooting_ = this->canFire();
    116116                    // Vector3 healthPosition = bestHealthPickup((this->target_->getWorldPosition() - this->getControllableEntity()->getWorldPosition()).length());
    117117                    // if ((this->getControllableEntity()->getWorldPosition() - healthPosition).length() < this->tolerance_)
Note: See TracChangeset for help on using the changeset viewer.