stacking Dynamic Objects

I am calling 52 dynamic objects on top of each other in a loop, here is the object

local card = display.newImageRect( ‘back.png’, orgcardx*2.20, orgcardy*2.15 ); card:rotate(90); card.x=DECKperm.x; card.y=DECKperm.y

physics.addBody( card, “dynamic”, { density = 0, friction = 0, bounce = 0 } ); 

When I stack 52 of these bad boys on top of each other, the cards explode out ONLY horizontally. Nothing moves vertically unless I wait a while and I watch the cards start to slide all over the place. 

I am setting gravity to 0,0 when calling physics

physics.start()      

physics.setGravity( 0, 0 )

How can I stack these cards without the magical explosion? 

Hi @lsilverman86coronalabs,

So these cards are stacked “on top” of each other, as in, the “z” dimension, with each card in front of the one below it? If so, you should probably make each card into a sensor object, so they don’t physically interact with each other (well, they would detect collisions, but as sensors, they wouldn’t exert any actual physical forces on the other cards).

Hope this helps,

Brent

I’ve been waiting for my post to be approved!

I fixed the issue by setting the card object as a sensor. Really awesome that dynamic objects can be sensors!

–prevent card objects from detecting and reacting to eachother by setting sensor

card.isSensor=true 

Bonus points for setting a CollisionFilter to prevent the card objects from detecting eachother on collision:

local cardCollisionFilter = { groupIndex = -1 } – negative groundIndex dont collide with eachother so card wont flip out when they are on top of eachother

physics.addBody( card, “dynamic”, { density = 0, friction = 0, bounce = 0, filter=cardCollisionFilter}  );

card.isSensor=true 

Thanks for the reply Brent! 

Hi @lsilverman86coronalabs,

So these cards are stacked “on top” of each other, as in, the “z” dimension, with each card in front of the one below it? If so, you should probably make each card into a sensor object, so they don’t physically interact with each other (well, they would detect collisions, but as sensors, they wouldn’t exert any actual physical forces on the other cards).

Hope this helps,

Brent

I’ve been waiting for my post to be approved!

I fixed the issue by setting the card object as a sensor. Really awesome that dynamic objects can be sensors!

–prevent card objects from detecting and reacting to eachother by setting sensor

card.isSensor=true 

Bonus points for setting a CollisionFilter to prevent the card objects from detecting eachother on collision:

local cardCollisionFilter = { groupIndex = -1 } – negative groundIndex dont collide with eachother so card wont flip out when they are on top of eachother

physics.addBody( card, “dynamic”, { density = 0, friction = 0, bounce = 0, filter=cardCollisionFilter}  );

card.isSensor=true 

Thanks for the reply Brent!