Collision Coordinates

Hi @ alfgago,
I don’t think there’s a way to pinpoint the location of a specific body part using only the event handler. However, you could do this mathematically based on the core X/Y of the object (both of which you can access at any time). It would take some up-front effort when you create the body, but seemingly it’s possible. Basically, you’d need to set “offset” coordinates for each body part in relation to 0,0 at the overall body center. Then, you could use those coordinates plus basic trigonometry (assuming the body might rotate) to determine where the body part is during a collision.

@polygonblog,
Just curious, is there an official bug report on file for this? If not, could you possibly create a bare-bones simple test instance of it, showing the bug? I could then try to push its priority and urge the Corona engineers to investigate and hopefully fix it.

Brent Sorrentino
[import]uid: 9747 topic_id: 32541 reply_id: 129679[/import]

Brent is right. Every collision body has vertices with coordinates relative to the physicsBody as a whole, if you read or keep track of these “shapes”, then you can loop over the vertices, apply trigonometric functions in case of rotation, and figure out which spot on a shape is colliding (you’ll need to go over which shape did the colliding first if the complex body is not completely convex in itself (they usually arent if they’re complex bodies) The shape id number is simple to discern: they’re numbered in the order they were added to the body.

It’s a rather tedious thing to have to program but I think it’s mathematically sound, since the component shapes themselves have to be convex only. [import]uid: 63787 topic_id: 32541 reply_id: 137187[/import]

Let me know if anybody tries this and it works, but I see it working just fine, on paper. Might have to cache all the vertices into a mapping from shape id to vertex list if the physics data struct doesn’t already have it set up that way (I suspect it might though). [import]uid: 63787 topic_id: 32541 reply_id: 137188[/import]

I’ve written this up in a library:

http://developer.coronalabs.com/code/physics-body-collision-location

Available in my collection:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html [import]uid: 8271 topic_id: 32541 reply_id: 137195[/import]

Cool :slight_smile: I’ll download it and try it out sometime. [import]uid: 63787 topic_id: 32541 reply_id: 137198[/import]

Brent is right. Every collision body has vertices with coordinates relative to the physicsBody as a whole, if you read or keep track of these “shapes”, then you can loop over the vertices, apply trigonometric functions in case of rotation, and figure out which spot on a shape is colliding (you’ll need to go over which shape did the colliding first if the complex body is not completely convex in itself (they usually arent if they’re complex bodies) The shape id number is simple to discern: they’re numbered in the order they were added to the body.

It’s a rather tedious thing to have to program but I think it’s mathematically sound, since the component shapes themselves have to be convex only. [import]uid: 63787 topic_id: 32541 reply_id: 137187[/import]

Let me know if anybody tries this and it works, but I see it working just fine, on paper. Might have to cache all the vertices into a mapping from shape id to vertex list if the physics data struct doesn’t already have it set up that way (I suspect it might though). [import]uid: 63787 topic_id: 32541 reply_id: 137188[/import]

I’ve written this up in a library:

http://developer.coronalabs.com/code/physics-body-collision-location

Available in my collection:

http://springboardpillow.blogspot.co.uk/2012/04/sample-code.html [import]uid: 8271 topic_id: 32541 reply_id: 137195[/import]

Cool :slight_smile: I’ll download it and try it out sometime. [import]uid: 63787 topic_id: 32541 reply_id: 137198[/import]