Collision detection issue

About vertex winding:

https://cmichel.io/understanding-front-faces-winding-order-and-normals

Tip: Don’t get hung up on the numbers he has assigned the vertices.  Pay attention to the order of traversal.  The order you traverse the vertices (or in the case of collision shapes order you define them) determines the winding (clockwise or counter-clockwise).

Finally I would reduce your code to this:

local rect = display.newRect( 200, 200, 80, 80) rect.name = "rect" physics.addBody( rect, "dynamic" ) rect:setLinearVelocity( 0, -330 ) function rect.collision( self, event ) if( event.phase == "ended" ) then if( event.other.name == "ball" ) then print("YO! HIT A BALL!") end end end rect:addEventListener( "collision" ) local ball = display.newCircle( 200, 100, 30 ) ball.name = "ball" physics.addBody( ball, "dynamic", { radius = 30 } )

Hello Sir @roaminggamer,

Purposely was trying to have collision boundaries more than that of an object body, but from above discussion it seems this can’t be done right??

Thanks for that vertices part.

Thanks and Regards,

Swanand Thakur.

You can make the body any size you like.

I simply wondered what you wanted to do and though perhaps you’d made a math error.

Note: You did have your winding in the wrong order.  So, whatever you choose to do with regards to custom physics bodies, be sure to follow the rules as per the docs.

https://docs.coronalabs.com/api/library/physics/addBody.html

https://docs.coronalabs.com/api/library/physics/addBody.html#bodytype-optional

https://docs.coronalabs.com/api/type/Body/bodyType.html

https://docs.coronalabs.com/guide/index.html#physics

https://docs.coronalabs.com/guide/physics/physicsBodies/index.html

AND BE SURE TO READ THIS (pay attention to IMPORTANT notes):

https://docs.coronalabs.com/guide/physics/physicsBodies/index.html#polygonal-bodies

Custom body vertices must be specified in clock-wise order and the body must be convex.  If you do not know what these terms mean, be sure to read the docs and research online. 

Tip: Non-convex bodies may seem to work, but will fail in certain cases.

Hello Sir @roaminggamer,

What I wanted to ask is if I have a rectangle

local rect = display.newRect( 200, 200, 80, 80)

then can I define the body collision outlines as

local shape = {

-40,-40,    ------upper left

40,-40,     ------upper right

40,80,      ------bottom right

-40,80      ------bottom left

}

Would the things work?? Would the collision be detected?

Regards,

Swanand Thakur. 

Yes, and you can observe the body by enabling debug draw mode:

https://docs.coronalabs.com/api/library/physics/setDrawMode.html

Thank you so much to all of you who have given their inputs in this above discussion.It has really helped heavily.

The problem is finally solved in all means.

Special thanks to Sir @roaminggamer, for his invaluable time and sharing precious knowledge. The above discussion was really fruitful, it taught me many useful and helpful concepts, which will definitely help me in prolong journey.

Thanks and Regards,

Swanand Thakur.

Hi there Swan!

I know this is about 4 years too late but I noticed there wasn’t an answer to this one still.

The fix is just one line

rec:addEventListener( "collision", onCollison )

the function name should included when you add an event listener, and not the object