Based on this: Counting instances at position
I made this script:
//script CountColliding(x,y,obj,0);
var ret;
ret = argument3;
show_debug_message(instance_place(argument0 /*x*/, argument1/*y*/,argument2 /*obj*/))
with(instance_place(argument0 /*x*/, argument1/*y*/,argument2 /*obj*/))
{
instance_deactivate_object(id)
ret = CountColliding(argument0,argument1,argument2,ret+1) ;
instance_activate_object(id)
}
return ret;
Where x
,y
are your objects in question x and y and obj
is the object to check collision with.
But I didn't like it very much so I made this one which I suppose it may be less error prone:
///CountColliding(obj)
var i,numOfColliding=0;
for (i = 0; i < instance_number(argument[0]); i += 1)
{
if(place_meeting(x,y,instance_find(argument[0],i)))
numOfColliding+=1;
}
return numOfColliding;
Which you use in your objects scope just bu passing as an argument the object that you want to check collision with.
Both return the number of colliding objects and both seem to work just fine but I don't know which one is more efficient performance wise.
Also I suppose you shouldn't use them in every step.