Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2015, 11:07:34 PM (8 years ago)
Author:
gania
Message:

fixed pointers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10722 r10725  
    5151
    5252        RegisterObject(CommonController);
    53 
    5453        //this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&LeaderController::action, this)));
    5554    }
     
    6059    }
    6160
     61    void CommonController::moveToPosition(const Vector3& target)
     62    {
     63        if (!this->getControllableEntity())
     64            return;
     65
     66        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     67        float distance = (target - this->getControllableEntity()->getPosition()).length();
     68        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     69        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
     70
     71       
     72        if (this->target_ || distance > 10)
     73        {
     74            this->getControllableEntity()->rotateYaw(-1.0f * 0.8f * rotateX);
     75            this->getControllableEntity()->rotatePitch(0.8f * rotateY);
     76        }
     77
     78        if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     79        {
     80            this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     81        }
     82        else if (distance > 100)
     83            this->getControllableEntity()->moveFrontBack(0.8f);
     84       
     85
     86
     87        if (distance < 100)
     88        {
     89            this->positionReached();
     90            bHasTargetOrientation_=false;
     91        }
     92    }
    6293 
    6394
Note: See TracChangeset for help on using the changeset viewer.