Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10075 in orxonox.OLD for branches/ai


Ignore:
Timestamp:
Dec 13, 2006, 11:01:36 PM (18 years ago)
Author:
tfahrni
Message:

AI can move without collisions

Location:
branches/ai/src/ai
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/ai/movement_module.cc

    r10071 r10075  
    2525
    2626#include "shell_command.h"
    27 /*SHELL_COMMAND(model, WorldEntity, loadModel)
    28 ->describe("sets the Model of the WorldEntity")
    29 ->defaultValues("models/ships/fighter.obj", 1.0f);*/
     27SHELL_COMMAND(aiacc, MovementModule, setAccleration);
    3028
    3129
     
    3331
    3432MovementModule::MovementModule(){
     33        //MovementModule::aa=100.0f;
     34        //a=100.0f;
    3535        //std::cout << "MovementModule created...\n";
    3636}
     
    4040
    4141
     42void MovementModule::setAccleration(float newValue)
     43{
     44        std::cout << "Setting a to: "<< newValue << "\n";
     45        //MovementModule::aa=newValue;
     46}
     47
     48
     49
     50
    4251float MovementModule::getSize(WorldEntity* object)
    4352{
     53        //does not work...
    4454        AABB* aabb = object->getModelAABB();
    4555        Vector a = aabb->getAxisX();
     
    8090        ////////////
    8191
    82         float a=50.0f;
    83         float keepDist= this->getSize(owner);//+ this->getSize(pl->getPlayable());
    84         std::cout << "Distance: " << keepDist << "\n";
     92        //if(aa<0)aa=100.0f;
     93        float a=200.0f;
     94        float vMax=200.0f;
     95       
     96        //float keepDist= this->getSize(owner);//+ this->getSize(pl->getPlayable());
     97        //std::cout << "Distance: " << keepDist << "\n";
    8598
    8699
    87100        Vector vectorToPlayer = playerAbsPos - myAbsPos;
    88101        float dist=vectorToPlayer.len();
    89         Vector nVectorToPlayer=vectorToPlayer/dist*(dist-keepDist);
    90 
    91 
    92 
     102        //Vector nVectorToPlayer=vectorToPlayer/dist*(dist-keepDist);
    93103
    94104
     
    96106        // get all npcs
    97107
    98         Vector tempNPCpos;
    99         Vector tempCorrectionVect;
    100         Vector antiCollision;
     108        Vector tmpNPCpos;
     109        float tmpDist;
     110        Vector tmpCorrectionVect;
     111        Vector antiNPCCollision;
    101112
    102113        for (ObjectList<NPC2>::const_iterator it = NPC2::objectList().begin();
     
    105116        {
    106117                if(*it==owner)continue;
    107                 tempNPCpos=(*it)->getAbsCoor();
    108                 tempCorrectionVect = myAbsPos-tempNPCpos;
    109                 tempCorrectionVect=tempCorrectionVect*1/(tempCorrectionVect.len());
    110                 //PRINTF(0)("class: %s\n", (*it)->getCName());
    111                 antiCollision=antiCollision+tempCorrectionVect;
     118                tmpNPCpos=(*it)->getAbsCoor();
     119                tmpCorrectionVect = myAbsPos-tmpNPCpos;
     120               
     121                tmpDist=tmpCorrectionVect.len()-16;
     122                if(tmpDist<0.1)tmpDist=0.1;
     123                tmpCorrectionVect=tmpCorrectionVect/(tmpDist*tmpDist);
     124               
     125                antiNPCCollision=antiNPCCollision+tmpCorrectionVect;
    112126        }
    113127
    114128
    115129
    116         Vector correction=antiCollision+nVectorToPlayer-v;
     130        Vector antiPlayerCollision=vectorToPlayer*(-1);
     131        tmpDist=antiPlayerCollision.len()-45;
     132        if(tmpDist<0.1)tmpDist=0.1;
     133        antiPlayerCollision=antiPlayerCollision/(tmpDist*tmpDist);
     134       
     135        Vector correction=antiPlayerCollision*50+antiNPCCollision*50+vectorToPlayer-v;
    117136        //Vector nCorrection=
    118137        correction.y=0;
     
    121140        v+=correction;
    122141
     142        float vLen=v.len();
     143        if(vLen>vMax)v/vLen*vMax;
    123144
    124145        //Move NPC...
     
    127148        //Rotate NPC
    128149        Vector view = v+correction;
    129         //if(vectorToPlayer.dot(view)<0){
    130                 //view = v.cross( Vector(0,1,0) ).getNormalized();
     150        //if(vectorToPlayer.dot(v)<0){
     151        //      view = v.cross( Vector(0,1,0) ).getNormalized();
    131152        //}else{
    132153                view = v.cross( Vector(0,-1,0) ).getNormalized();
    133154        //}
    134155        //if(dist<keepDist)view=view*-1;
    135         owner->setAbsDir( Quaternion( view, Vector(0,1,0)));
    136         //owner->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),1.5);
     156        //owner->setAbsDir( Quaternion( view, Vector(0,1,0)));
     157        owner->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),1.1);
    137158}
    138159
  • branches/ai/src/ai/movement_module.h

    r10071 r10075  
    88
    99class MovementModule : public AIModule{
     10       
    1011 public:
    1112   MovementModule();
    1213   virtual ~MovementModule();
    1314   virtual void process();
     15   static void setAccleration(float newValue);
    1416 private:
    1517         Vector v;
    1618         float getSize(WorldEntity* object);
     19         static float aa;
    1720};
    1821
Note: See TracChangeset for help on using the changeset viewer.