# Colobot Forum - International Colobot Community

Full Version: Radius param for search()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Would be nice for path finding & detecting objects near a point away from the robot.

And maybe:

object items[] = searchall(cat[, pos], radius);

I actually already did this myself.
searchall() is a great idea too
I like the idea of using all radar parameters.
But using angle and focus might be confusing.

Maybe if the search function has an orientation of it's own,
direction("search position") could be relative 0 angle for search.

So it could be used and calculated in terms of right angles.

Radius was just max parameter by a different name.

Edit: Or just leave out angle and focus, replaced by position. search(cat, pos, min, max, sens, filter);
Radius for search can be done in a custom CBOT function pretty easily.

Returning an array of all objects of certain category is even easier.

I bet angular limitations are possible as well. Tho I don't see much of a use for those. You can choose a percise spot to look at anyway.

Example:
Code:
```object object::bettersearch(int cat, point pos, float rmin, float rmax) {     // Generate objects list          object objects[];     int i = 0;     float range = 0;     int size;          while(true)     {         objects[i] = radar(cat, 0, 360, range);         if(objects[i] == null)         {             size = i;             break;         }                  range = distance(this.position,objects[i].position)+0.1;         i++;     }          // Objects list ready     // One could 'return objects;' here to get searchAll          float distances[];     int result = nan;          for(i=0;i<size;i++)     {         distances[i] = distance(pos,objects[i].position); // Determine distances         if (distances[i] < rmin) distances[i] = 1000; // Trim objects too close                  if (distances[i] < rmax) // Locate closest object         {             rmax = distances[i];             result = i;         }     }          // Return the result          if (result == nan)     {         message("Object not found",DisplayError);         return null;     }     else return objects[result]; }```

I didn't post in a while now did I?
This is similar to what I was doing at first, but it was
very slow to call such a function hundreds of times per minute.
Which then made creating a path finding algorithm pretty pointless.

The game engine already has this functionality, it only needed to be enabled.
The A* algorithm I have now, is as fast and even more accurate than goto().

I imagine search() and searchall() as being built-in functions of
the satellite that is usually in orbit above your position.