KAgent steer

From KokkugiaWiki

arguments:
target (kVec) - the position which the agent is attempting to steer towards.
threshold (float) - a distance at which it will ignor the steer target.

returns:
a vector to enable the agent to steer toward the target. this vector is adjusted based on the agents maximum velocity (maxVel) and maximum steering force (maxForce).

 // steer
 kVec steer(kVec target, float threshold) {
    target.minus(pos); 
    float dist = target.length();

    if (dist > 0 && dist < threshold) {
      target.normalize();
      target.scale(maxVel);
      target.minus(vel); 
      target.limit(maxForce); 
    } 
    else {
      target = new kVec(0,0,0);
    }
    return target;
  }
Views