International Journal of Computer Games Technology / 2015 / Article / Alg 7

Research Article

Artificial Intelligence in Video Games: Towards a Unified Framework

Algorithm 7

Dodging a straight line projectile. This function assumes that the projectile is not penetrating.
void  dodge_projectile(Unit  u, Projectile  p)
{
 //Create a ray for the projectile course
Ray r(p->position(), p->velocity());
 //Get a list of objects intersecting the ray
ObjectList is = intersection(r, p->radius());
 //Only dodge if u is the first object to intersect the ray
if  (is.front() == u)
 {
  //Is u exactly on the projectile course?
  if  (r.passthru(u->position()))
  {
   //Move perpendicularly by a distance equal to the sum of bounding radiuses
   u->move(u->position() + r.normal()(p->radius() + u->radius()));
   return;
  }
  //Project the unit position on the projectile course
  Vector pr = r->project(u->position());
  //Get a normal to the projectile course with a norm equal to the distance between
   the unit position and its projection
  Vector mv = u->position() − pr;
  //Rescale it to the width of the intersection
  mv  = (p->radius()   (mv.norm()   u->radius()))/mv.norm();
  //Follow the normal to avoid collision
  u->move(u->position() + mv);
 }
}

We are committed to sharing findings related to COVID-19 as quickly as possible. We will be providing unlimited waivers of publication charges for accepted research articles as well as case reports and case series related to COVID-19. Review articles are excluded from this waiver policy. Sign up here as a reviewer to help fast-track new submissions.