# Cross Referencing Objects in Loops

0 favourites
• 4 posts
From the Asset Store
In this fun game you must try to complete the path for the car to pass before time runs out, agility and reasoning are a
• 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 :)

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• 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.

• You can make a second family with the same objects, and use what R0J0hound said

• Thanks R0J0hound and 7Soul. I shall give this a go. I didn't realise multiple inheritance was possible, neat :)

• 4 posts