Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10038 in orxonox.OLD for branches/playability/src


Ignore:
Timestamp:
Dec 10, 2006, 11:49:38 PM (18 years ago)
Author:
nicolasc
Message:

added some div by zero checkings; problem still exists

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/playability/src/world_entities/projectiles/swarm_projectile.cc

    r10037 r10038  
    156156Vector SwarmProjectile::newDirection(Vector curDirection, Vector estTargetDir, float angle)
    157157{
     158  if (unlikely(curDirection.len() == 0))
     159    return curDirection;
    158160  printf("recalculating direction\n");
    159161  float tmp = angleDeg ( curDirection, estTargetDir);
     
    209211  this->shiftCoor(v);*/
    210212
     213  float projectileVelocity = this->velocity.len();
    211214  if (target != NULL){
    212     float tti = this->target->getRelCoor().len() / this->getVelocity().len();
     215    float tti;  //Time To Impact
     216    float targetVelocity = this->target->getVelocity().len();
     217    if (unlikely(projectileVelocity == 0 && targetVelocity == 0)) // TODO calculate this reasonably
     218      tti = 1; // we do have a problem....
     219    else
     220      tti = this->target->getRelCoor().len() / sqrt ( projectileVelocity * projectileVelocity + targetVelocity * targetVelocity);
    213221    Vector estTargetDir = (this->target->getRelCoor() + this->target->getVelocity()) * tti;
    214222    this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * time );
    215223  }
    216224  else
    217     velocity *= maxVelocity / velocity.len(); // set speed to max
     225    if (likely(projectileVelocity != 0))
     226      this->velocity *= maxVelocity / projectileVelocity; // set speed to max
    218227
    219228
Note: See TracChangeset for help on using the changeset viewer.