Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 29, 2015, 6:36:21 PM (8 years ago)
Author:
gania
Message:

started working on pickups

File:
1 edited

Legend:

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

    r10886 r10888  
    172172        }
    173173    }
    174    
     174    void FightingController::dodgeTowards (Vector3& position)
     175    {
     176        Vector3 thisPosition = this->getControllableEntity()->getPosition();
     177        Vector3 diff = (position - thisPosition);
     178        float diffLength = diff.length();
     179        Vector3 diffUnit = diff/diffLength;
     180        float factor = 300.0f;
     181        if (diffLength < 300)
     182        {
     183            this->setTargetPosition(position);
     184            return;   
     185        }
     186        else if (diffLength < 600)
     187            factor = 400.0f;
     188        else if (diffLength < 1000)
     189            factor = 700.0f;
     190        else
     191            factor = 1000.0f;
     192        float x = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     193        float y = CommonController::randomInRange (400, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
     194        float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
     195        this->setTargetPosition(thisPosition + Vector3(x,y,z) + diffUnit * factor);
     196        // orxout(internal_error) << "Dodging towards " << Vector3(x,y,z)  << endl;
     197        this->boostControl();
     198    }
    175199    void FightingController::dodge(const Vector3& thisPosition, Vector3& diffUnit)
    176200    {
     
    179203        float x = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    180204        float y = CommonController::randomInRange (100, 800) * (CommonController::randomInRange(0,1) <= 0.5 ? 1 : -1);
    181         float z = (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
     205        float z = diffUnit.z == 0 ? 0 : (1/diffUnit.z) * (-x * diffUnit.x - y * diffUnit.y);
    182206        this->setTargetPosition(thisPosition + Vector3(x,y,z) + (this->deltaHp < 0 ? -diffUnit * 450.0f : diffUnit * 100.0f));
    183207        this->boostControl();
Note: See TracChangeset for help on using the changeset viewer.