• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker How to Handle instance_position With Overlapping Objects?

F

Feather Dreams

Guest
Hello!

I'm running into a bit of an issue:

I need to run a check on all of the instances of a given object type that are present at a certain set of x,y coordinates, and it is quite likely that there would be more than one there.

However, when retrieving these objects, only one is returned.

Is there a way around this?

Thanks!

For the sake of clarity, here is the code I'm currently using:

Code:
wallCheck = false;
i = 0;
while(i <= spriteWidth && wallCheck == false){
    inst = instance_position(x+i+argument0, y+argument1, obj_abstract_ledge);
    if(!falling){
        wallCheck = inst != noone && inst.height > currentHeight+8;
    } else {
        wallCheck = inst != noone && inst.height > currentHeight;
    }
    i+=8;
}
return wallCheck;
Essentially, I am looking to see if there is an "obj_abstract_ledge" at a given position, and at a height higher than the player's current height. ('height' here being a faked 'Z' axis, as opposed to the y position). As I'm now trying to stack, for example, a fence on top of a ledge, with the fence having a height of 48 and the ledge a height of 32, I'm running into (I suspect) an issue where the ledge is detected by 'instance_position' and correctly ignored since the player is currently on top of it. However, the fence is then being overlooked.

How can I validate each object? The objects are currently on separate layers, but I would like a solution which is also workable for objects on the same layer, for the sake of future projects.

Thank you!
 
Top