[Orxonox-commit 2378] r7093 - code/branches/presentation3/src/orxonox/controllers
landauf at orxonox.net
landauf at orxonox.net
Wed Jun 2 22:45:14 CEST 2010
Author: landauf
Date: 2010-06-02 22:45:14 +0200 (Wed, 02 Jun 2010)
New Revision: 7093
Modified:
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
Log:
Fixed strange movements of the Drone while shooting. Also the drone shoots now every tick instead of every second. It's a real killer-drone!
Modified: code/branches/presentation3/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/presentation3/src/orxonox/controllers/DroneController.cc 2010-06-02 20:10:44 UTC (rev 7092)
+++ code/branches/presentation3/src/orxonox/controllers/DroneController.cc 2010-06-02 20:45:14 UTC (rev 7093)
@@ -50,6 +50,7 @@
this->owner_ = 0;
this->drone_ = 0;
+ this->isShooting_ = false;
this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&DroneController::action, this)));
@@ -74,27 +75,14 @@
{
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
- float distanceToTargetSquared;
+ float distanceToTargetSquared = 0;
- if (target_) {
- const Vector3& locTargetDir = getDrone()->getOrientation().UnitInverse()*((getDrone()->getWorldPosition())-(target_->getWorldPosition())); //Vector from Drone To target out of drones local coordinate system
- distanceToTargetSquared = locTargetDir.squaredLength();
- }
+ if (this->target_)
+ distanceToTargetSquared = (getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
random = rnd(maxrand);
if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
this->searchNewTarget();
-
- if (random < 50 && this->target_ && distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
- {
- this->isShooting_ = true;
- this->aimAtTarget();
- drone_->rotateYaw(targetPosition_.x); //face target
- drone_->rotatePitch(targetPosition_.y);
- drone_->fire(0);
- this->isShooting_ = false;
- }
-
}
/**
@@ -107,15 +95,29 @@
{
if (this->getDrone() && this->getOwner())
{
+ if (this->target_)
+ {
+ float distanceToTargetSquared = (this->getDrone()->getWorldPosition() - this->target_->getWorldPosition()).squaredLength();
+ if (distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
+ {
+ this->isShooting_ = true;
+ this->aimAtTarget();
+ this->getDrone()->fire(0);
+ }
+ }
+
float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
- if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) {
+ if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared)
+ {
this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
}
- else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
+ else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared)
+ {
this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
}
- else if(!isShooting_) {
+ else if (!this->isShooting_)
+ {
float random = rnd(2.0f);
float randomSelection = rnd(6.0f);
if((int)randomSelection==0) drone_->moveUpDown(random);
@@ -125,6 +127,8 @@
else if((int)randomSelection==4) drone_->rotatePitch(random);
else if((int)randomSelection==5) drone_->rotateRoll(random);
}
+
+ this->isShooting_ = false;
}
SUPER(AIController, tick, dt);
More information about the Orxonox-commit
mailing list