Find all objects with instance_place()

trg601

Member
Context:
So I am working on this (very simple) 3D collision system, where it checks if there is a 2D collision and X/Y, and then checks if the z values intersect for the colliding objects. It has some kinks, but it works fairly well.

The big problem is that I am using the function instance_place() to find the object, and if there are more than one object, it only collides with one. (which is NOT good)

Question:
Is there a way to get an array (or something similar) of all objects that collide with place_meeting()?

Thank you!
 

jo-thijs

Member
Yup, either:
Code:
var list, length = 0;
var result, n = 0;
var cid;

while true {
    cid = instance_place(X, Y, OBJ);
    if cid {
        result[n++] = cid;
        instance_deactivate_object(cid);
    } else
        break;
}

for(var i = 0; i < n; i++)
    instance_activate_object(result[i]);
or this:
Code:
var result, n = 0;
var px = x;
var py = y;

x = X;
y = Y;

with OBJ
    if place_meeting(x, y, other)
        result[n++] = id;

x = px;
y = py;
 

trg601

Member
Thank you both! I think I will use that handy script from GMLscripts, but it is wonderful to know I have multiple options :)
 
Top