How to find automous agents within range

[sloved]

` void seek(PVector target) {
    // only run if mousecursor is pressed
    if (mousePressed) {
      // if creatures are nerby target
      float nerby=(10);
      for (Creature c : creatures) {
        float d = PVector.dist(target, c.position);
        if (d == nerby) {
          fill(a); // pink
          PVector desired = PVector.sub(target, position);
          desired.normalize();
          desired.mult(maxspeed);
          PVector steer = PVector.sub(desired, velocity);
          steer.limit(maxforce);
          applyForce(steer);
        }
      }
    } else {
      fill(c); //blue
    }
  }`

d<=nearby

Regards

Chrisir

Yeah, 10 is also very small - maybe try 40

hey thanks for the reply but i’ve found another soloution to the problem and its works !

1 Like