Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

tried to fix fighting whn fps is low

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.