Polygon body shape problem

hi…,
i have an object with this physics:

physics.addBody(rat1,"dynamic", {density=1.0, friction=0.1, bounce=0.5, radius=25})


and i have a collision function …and it works well

function onHit(e) if(e.phase == "began") then if(e.object1.type == "stone" and e.object2.type == "rat") then x=e.object2.x y=e.object2.y Runtime:removeEventListener("enterFrame", moveRat) transition.to(rat1, {time=100, alpha=0}) rat1.bodyType="static" rat1:removeSelf() local sheet2 = sprite.newSpriteSheet( "Objects/ex.png", 100, 100) local spriteSet2 = sprite.newSpriteSet(sheet2, 1, 24) ratboom = sprite.newSprite( spriteSet2 ) ratboom.timeScale = 0.35 ratboom.x=x ratboom.y=y ratboom:play() transition.to(ratboom, {time=1000, alpha=0}) stoneBoom() end end end Runtime:addEventListener("collision", onHit)
the problem is when i erase the previous physics line, and use the following physics instead:

squareShape ={ -20,-10, 20,-10, 20,10, -20,10 } physics.addBody(rat1,"dynamic", {density=1.0, friction=0.1, bounce=0.5, shape=squareShape}) physics.setDrawMode( "hybrid" )
the body is created but the collision listener doesn’t work … However the collision is detected and the other objects are affected through ‘bouncing’ when a hit between them and this object happened !!

i don’t know why it only works when using radius !! [import]uid: 96659 topic_id: 18764 reply_id: 318764[/import]

Sorry, are you saying that adding a radius prevents the collision listener from working?

If so could you provide plug and play code demonstrating this, please?

What version of Corona are you using?

Peach :slight_smile: [import]uid: 52491 topic_id: 18764 reply_id: 72392[/import]

Hi Peach,

i’m saying that adding the shape prevents the collision listener from working … but still affects the other object through bouncing and so on

… the radius makes it works well…even the listener action or affecting the other objects

& i’m using ver. 2011.591
:slight_smile: [import]uid: 96659 topic_id: 18764 reply_id: 72394[/import]

0o0ok … i think i solved it :smiley:
i rearranged the conditions and turned them into this:

if(e.object1.type == "rat" and e.object2.type == "stone")  

and so, the listener is working now
i’ve just made the first object be the rat and the second be the stone
… maybe it’s recommended to assign the created polygon-shape -if u have- to the first argument of the collision function … hence the second (stone) was a radius-shape or any thing else

just don’t assign the radius shape to the event.object1 when u have a polygon shape
… that’s what i understood !! [import]uid: 96659 topic_id: 18764 reply_id: 72416[/import]

Hey, OK, so object1 was the rat. That makes sense :slight_smile:

And no, you don’t want to try assigning a radius and a custom shape - it’s either or.

Glad you’ve got it sorted!

Peach :slight_smile: [import]uid: 52491 topic_id: 18764 reply_id: 72581[/import]