# Cross Referencing Objects in Loops

Get help using Construct 2

### » Sun Oct 28, 2012 9:24 pm

Hi

I've written some game animation that uses very simple 3D transformations. Nothing too complex...

position.X =((x*perspective)/z)+screencentreX
position.Y =((y*perspective)/z)+screencentreY

(where x,y,z, etc are object instance variables)

Now, I would like to loop through the objects (I'm using a family called 3DSprite) and using math, see if any of the 3D objects are overalapping each other in 3D space (everything is a sphere, so the math is a simple distance to center of both 3D objects being less than sum of object radius). Note all 3D vector, radius and calculated 2D screen position values are held in family in instance variables for reference.

I'm getting my self tied in knots. I can't seem to see to find an easy way to "nested loop" through all the 3DSprite family objects. To my mind it's a loop (A) through the object family followed (sub event?) loop (B) through the objects again. Then, comparing (A) instances variables with (B) variables if (A) object != (B) objects.

Any help greatly appreciated. Once I crack this, then 3D collision math is easy and I can blend 2D with a nice 3D animation :)

B
13
S
2
Posts: 27
Reputation: 1,899

### » Sun Oct 28, 2012 11:07 pm

This works if there is only one object type in a family:

For each 3DSprite
for each Sprite
do comparison...

In this case 3DSprite and Sprite allow for two separate picked instance of sprite.
B
97
S
36
G
131
Posts: 5,519
Reputation: 83,476

### » Mon Oct 29, 2012 4:32 am

You can make a second family with the same objects, and use what R0J0hound said
B
87
S
22
G
15
Posts: 1,041
Reputation: 15,343

### » Mon Oct 29, 2012 6:50 am

Thanks R0J0hound and 7Soul. I shall give this a go. I didn't realise multiple inheritance was possible, neat :)
B
13
S
2
Posts: 27
Reputation: 1,899