Imperial
Member
I believe the only missing argument of instance_nearest function is the notme argument
Like the collision_circle...It has the notme to avoid the object from detecting It self
I tried this Scripts but It doesn't work as It should be
and this one
YoyoGames, can you please add the notme argument to the instance_nearest function please
Like the collision_circle...It has the notme to avoid the object from detecting It self
I tried this Scripts but It doesn't work as It should be
Code:
/// instance_nth_nearest(x,y,obj,n)
//
// Returns the id of the nth nearest instance of an object
// to a given point or noone if none is found.
//
// x,y point coordinates, real
// obj object index (or all), real
// n proximity, real
//
/// GMLscripts.com/license
{
var pointx,pointy,object,n,list,nearest;
pointx = argument0;
pointy = argument1;
object = argument2;
n = argument3;
n = min(max(1,n),instance_number(object));
list = ds_priority_create();
nearest = noone;
with (object) ds_priority_add(list,id,distance_to_point(pointx,pointy));
repeat (n) nearest = ds_priority_delete_min(list);
ds_priority_destroy(list);
return nearest;
}
Code:
var xx,yy,obj,nearest;
xx = argument0;
yy = argument1;
obj = argument2;
nearest = noone;
dist = -1;
for(i = 0; i < instance_number(obj); i++)
{
var o,d;
o = instance_find(obj,i);
d = point_distance(xx,yy,o.x,o.y);
if(o != id)
{
if(nearest == noone || d < dist)
{
nearest = o;
dist = d;
}
}
}