Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 15, 2010, 6:12:13 PM (14 years ago)
Author:
gnadler
Message:

rockets get target but moveToPosition function does not work correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/rocket/src/modules/weapons/RocketController.cc

    r6904 r6905  
    6363    {
    6464                haha++;
     65               
    6566
    6667        SimpleRocket *rocket = static_cast<SimpleRocket*>(this->getControllableEntity());
     68                if (haha<30)rocket->setVelocity(rocket->getVelocity()*1.03);
    6769                if (this->target_) {
    68                 rocket->rotatePitch(0.5);
    69                 rocket->rotateYaw(0.5);
     70                        this->setTargetPosition();
     71                        this->moveToTargetPosition();
     72               
    7073                }
    71                 rocket->setVelocity(rocket->getVelocity()*1.03);
     74               
     75                if (haha>500) rocket->setDestroy();;
    7276       
    7377        }
     
    8084        }
    8185
     86        void RocketController::setTargetPosition() {
     87                this->targetPosition_=this->target_->getPosition();
     88                //this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(),this->getControllableEntity()->getVelocity().length() , this->target_->getPosition(), this->target_->getVelocity());
     89        }
     90        void RocketController::moveToTargetPosition() {
     91                this->moveToPosition(this->targetPosition_);
     92        }
    8293
    83         void RocketController::setTarget(Pawn* target) {
     94
     95
     96        void RocketController::setTarget(WorldEntity* target) {
    8497                this->target_ = target;
     98                COUT(0)<<"got target\n";
    8599        }
     100
     101        void RocketController::moveToPosition(const Vector3& target)
     102    {
     103       if (!this->getControllableEntity())
     104            return;
     105
     106           COUT(0)<<"moving";
     107
     108        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     109        float distance = (target - this->getControllableEntity()->getPosition()).length();
     110
     111        if (this->target_ || distance > 10)
     112        {
     113            // Multiply with 0.8 to make them a bit slower
     114                         this->getControllableEntity()->rotateYaw(-0.2f * sgn(coord.x) * coord.x*coord.x);
     115            this->getControllableEntity()->rotatePitch(0.2f * sgn(coord.y) * coord.y*coord.y);
     116                       
     117        }
     118    }
    86119
    87120
Note: See TracChangeset for help on using the changeset viewer.