Why won't this block fall down?

I’m having a problem where blocks won’t fall down holes, even though the size should be just right.

I’ve made a simple example to show you:

[lua]local smallblock1 = display.newImageRect( “block_stone.png”, 32, 32 )
smallblock1:setReferencePoint( display.TopLeftReferencePoint )
smallblock1.x = 0
smallblock1.y = 448
physics.addBody( smallblock1, “static”, { density=1, friction=0.3, bounce=0.2 } )

–BIG BLOCK
local bigBlock = display.newImageRect( “block_4square.png”, 64, 64 )
bigBlock:setReferencePoint( display.TopLeftReferencePoint )
bigBlock.x = 32
bigBlock.y = 384
physics.addBody( bigBlock, { density=1, friction=0.3, bounce=0.2 } )
bigBlock.isFixedRotation = true

local smallblock2 = display.newImageRect( “block_stone.png”, 32, 32 )
smallblock2:setReferencePoint( display.TopLeftReferencePoint )
smallblock2.x = 96
smallblock2.y = 448
physics.addBody( smallblock2, “static”, { density=1, friction=0.3, bounce=0.2 } )[/lua]

I’ve set the Reference Point to the top left to make it easier to debug, but the result is the same even if it’s in the center.

The above code should give just enough pixels (64) between the two smaller blocks to make the big block fit, but it won’t. If I remove either of the smaller blocks it’ll fall down.

If I take a screenshot in hybrid/debug mode I can measure the size of the big block to 65px and the gap under it to 63px. I’d like to believe it should really be 64px/64px.

[import]uid: 13180 topic_id: 14374 reply_id: 314374[/import]

Move the small blocks further apart, if it falls then you know its because they’re placed incorrectly. If not try this when you make the new big block.

physics.addBody( bigBlock, "dynamic", { density=1, friction=0.3, bounce=0.2 } )

[import]uid: 68741 topic_id: 14374 reply_id: 53133[/import]

… i’m wondering if you removed the friction if they’d be able to slide down. friction is “sticking power” i believe. namely, consider with friction you have blocks of sandpaper, rather than blocks of ice. [import]uid: 13859 topic_id: 14374 reply_id: 53155[/import]

@kennw: No, changing the friction doesn’t make any difference.
Moving the smaller blocks further apart would of course let the big block fall through. The problem is that I’m placing a lot more blocks, and they’re all based on a 32px grid. Moving blocks around by 1 pixel here and there would be a lot of work, and shouldn’t really be needed.

If I measure the sizes on the blocks using the normal draw mode they should fit perfectly. However, when using the debug draw mode I can see that the blocks have gotten 1px higher and 1px wider.

[import]uid: 13180 topic_id: 14374 reply_id: 53191[/import]

have you tried placing the big block higher so it will start moving before it gets to the small blocks [import]uid: 7911 topic_id: 14374 reply_id: 53192[/import]

Or perhaps you could offset the positioning in a easy way since you know the offset.

[code]
local offset = 1

local myBlock = whatever
myBlock.x = 200 - offset – Or plus offset depending on position
[/code] [import]uid: 84637 topic_id: 14374 reply_id: 53196[/import]

everybody seem to try to find a workaround, but this is apparently is a bug. There is an invisible border around display objects, which makes it bigger then its real size. [import]uid: 46529 topic_id: 14374 reply_id: 53219[/import]

Yes, I agree with culutas.

None of the workarounds are really that great. The problem is that the calculated physical size is larger than it really should be. This might not affect most games, but if your game needs pixel perfection then it’s a problem. [import]uid: 13180 topic_id: 14374 reply_id: 53224[/import]

Until this is resolved I suggest the following using a shape parameter to reduce the size of the physics body by one pixel all the way around.

For a top-left referenced box try:

  
myBox = display.newRect(x,y,w,h)  
  
topLeftX = myBox.x  
topLeftY = myBox.y  
topRightX = myBox.width + myBox.x  
topRightY = topLeftY  
bottomRightX = topRightX  
bottomRightY = myBox.height + myBox.y  
bottomLeftX = topLeftX  
bottomLeftY = bottomRightY  
  
myShape = {topLeftX + 1,topLeftY + 1, topRightX - 1,topRightY + 1,  
 bottomRightX -1,bottomRightY - 1, bottomLeftX + 1,bottomLeftY - 1}  
  

insert shape = myShape into your addBody parameters.

a variation should work for center referenced objects.

Hope this 1.makes sense and 2.helps.

[import]uid: 64596 topic_id: 14374 reply_id: 53240[/import]

That makes a lot of sense. I’ll try it out. Thank you! [import]uid: 13180 topic_id: 14374 reply_id: 53417[/import]

It occurs to me now that the shape property uses points based on a center reference point. So the above solution will require modification to accommodate that. Still, the idea is sound. Please let us know if this solves the problem (for now) and exactly what you did.

And, IF it works, you’re welcome :slight_smile: [import]uid: 64596 topic_id: 14374 reply_id: 53459[/import]