Mapping an Irregular Polygon Display Object to an Added Body

Hi all,

What is the best known method to align an irregular (but convex) physics body with an irregular display object of the same shape? I’m having trouble discovering how to get the new display object to match the body. They are always offset, I guess because one has its origin about the centroid and the other around the center of a bounding box?

When I tried using the calculated centroid of the polygon as well as the height and width of the bounding box for the display object and then converting that into correct anchor points, I get a perfect match between the two, but this seems to modify other object’s anchor points and screws up the alignment of any other polygon I have on the screen.

Edit:

I think I figured it out, seems like you have to have an offset table of vertices for the display object and physics object so they line up.

Interesting. I have the same problem as written here: https://forums.coronalabs.com/topic/58361-physicsaddbody-chain-not-aligned-with-polygon-of-same-shape/?p=301952

can you share your code? I am on the way of calculating centroid etc, but if you have something that’s already working, the better.
 

Hi @max00,

I’ve used this code module with great success. It’s actually brilliant. :slight_smile:

[https://code.coronalabs.com/code/create-complex-non-convex-bodies](https://code.coronalabs.com/code/create-complex-non-convex-bodies\)

Take care,

Brent

Thanks Brent, after a couple days of experimenting, I am very close to having a satisfactory solution :slight_smile: actually most of my problems come from convex shapes, and I might have found a reliable way to detect collision for my very specific case … :slight_smile: alignment is dealt with now, collision works perfectly except when one of the sensor objects ends completely into another one. I’ll have to test this insight tomorrow!

Interesting. I have the same problem as written here: https://forums.coronalabs.com/topic/58361-physicsaddbody-chain-not-aligned-with-polygon-of-same-shape/?p=301952

can you share your code? I am on the way of calculating centroid etc, but if you have something that’s already working, the better.
 

Hi @max00,

I’ve used this code module with great success. It’s actually brilliant. :slight_smile:

[https://code.coronalabs.com/code/create-complex-non-convex-bodies](https://code.coronalabs.com/code/create-complex-non-convex-bodies\)

Take care,

Brent

Thanks Brent, after a couple days of experimenting, I am very close to having a satisfactory solution :slight_smile: actually most of my problems come from convex shapes, and I might have found a reliable way to detect collision for my very specific case … :slight_smile: alignment is dealt with now, collision works perfectly except when one of the sensor objects ends completely into another one. I’ll have to test this insight tomorrow!