Outlined physics body is not the right shape.

I’m having an issue where I’m trying to create a physics body for a sprite using outlines but the physics body is not remotely close to what the shape should be. 

I’ve submitted a bug report for this (#6098508), but I’m curious as to if this is expected behavior by Corona. I really would like to use outlines for environmental physics bodies like hills and bumpy roads with weird shapes, but if this type of issue happens often then it could be problematic.

There’s an example image here. Also you can download the test program via Google Drive here.

Hi @jhow,

I assume you experimented with changing the “coarsenessInTexels” value of the “graphics.newOutline()” call? That can make a vast difference on how the outline is traced on the object.

Another suggestion I have, if you’re implementing a side-scrolling game with hills and bumpy roads, is to use the “edge shape” physics body constructor. This somewhat-unknown method lets you create all kinds of lovely curvy physics surfaces (uninterrupted) and circumvents the occasional issue where, if two “tiles” butt up against each other and they each have a physics body, the wheel/car can “snag” when it crosses over that little joining corner point.

https://docs.coronalabs.com/api/library/physics/addBody.html#edge-shape-chain-body

Best regards,

Brent

@Brent Sorrentino,

Thanks for the response.

Yes, I did play around with the coursenessInTexels and still did not get the results I was looking for. From 2->4 I got something similar to above. Once I hit five, it start getting closer to encompassing the full shape, but because going up in courseness lowers the resolution, the shape was not refined/smooth enough. It should be the other way around, as I move to a lower number then it should encompass the shape better.

I was actually peeking at the edge shape stuff previously. But unfortunately, it’s kind of hard to understand what the heck it is from the documentation. Do you guys have any examples on how to use it properly? I searched for some, but couldn’t find any.

Outlines seemed more straightforward because I can just have an artist create the environment (any hills, ground, roads, etc.) for me to scroll across the screen in my sidescroller. With edges it seems less easy to use to the environmental artwork I get because I’ll have to manually input coordinates, right?

Hi @jhow,

I agree that, in the case you’ll be creating some pretty random level designs, “edge shape” bodies probably won’t be ideal.

How many types of ground/hills/roads do you expect to create to make up levels? 10? 20? 50+? Personally, because I’m really anal about physics, I still prefer to hand-tailor my physics bodies shapes to the art I’m using, potentially via PhysicsEditor or another third-party utility. This gives me the exact and pixel-perfect tracing of the art, satisfying my perfectionist nature. :slight_smile: Then I set up a table containing those shapes by key-value pairs (names) which I’ll later associate with the art. When the art piece/tile gets put on screen, I read its body info from the table and apply it. Basically, the newOutline() method has always been a “usually fine but not always perfect” approach… and that’s OK for many people, but I prefer making sure it’s perfect in every instance and I’ll take the extra effort to make sure it is.

Brent

Basically, the newOutline() method has always been a “usually fine but not always perfect” approach… and that’s OK for many people, but I prefer making sure it’s perfect in every instance and I’ll take the extra effort to make sure it is.

My point, though, is that in my example, the outline is not even remotely close to “fine but not always perfect”. The physics body doesn’t even cover a quarter of the shape even with a low courseness argument, which should be even finer. Whatever way newOutline calculates the vertices seems to be broken.

Does Corona intend to look into this?

Hi @jhow,

I see you filed a bug report on this, yes? If so, thanks, and now we have it on file, but I’m not sure how soon it will be prioritized among other bugs. Admittedly that API could use improvement, as the trace results can (but not always) vary widely.

Brent

Hi @jhow,

I assume you experimented with changing the “coarsenessInTexels” value of the “graphics.newOutline()” call? That can make a vast difference on how the outline is traced on the object.

Another suggestion I have, if you’re implementing a side-scrolling game with hills and bumpy roads, is to use the “edge shape” physics body constructor. This somewhat-unknown method lets you create all kinds of lovely curvy physics surfaces (uninterrupted) and circumvents the occasional issue where, if two “tiles” butt up against each other and they each have a physics body, the wheel/car can “snag” when it crosses over that little joining corner point.

https://docs.coronalabs.com/api/library/physics/addBody.html#edge-shape-chain-body

Best regards,

Brent

@Brent Sorrentino,

Thanks for the response.

Yes, I did play around with the coursenessInTexels and still did not get the results I was looking for. From 2->4 I got something similar to above. Once I hit five, it start getting closer to encompassing the full shape, but because going up in courseness lowers the resolution, the shape was not refined/smooth enough. It should be the other way around, as I move to a lower number then it should encompass the shape better.

I was actually peeking at the edge shape stuff previously. But unfortunately, it’s kind of hard to understand what the heck it is from the documentation. Do you guys have any examples on how to use it properly? I searched for some, but couldn’t find any.

Outlines seemed more straightforward because I can just have an artist create the environment (any hills, ground, roads, etc.) for me to scroll across the screen in my sidescroller. With edges it seems less easy to use to the environmental artwork I get because I’ll have to manually input coordinates, right?

Hi @jhow,

I agree that, in the case you’ll be creating some pretty random level designs, “edge shape” bodies probably won’t be ideal.

How many types of ground/hills/roads do you expect to create to make up levels? 10? 20? 50+? Personally, because I’m really anal about physics, I still prefer to hand-tailor my physics bodies shapes to the art I’m using, potentially via PhysicsEditor or another third-party utility. This gives me the exact and pixel-perfect tracing of the art, satisfying my perfectionist nature. :slight_smile: Then I set up a table containing those shapes by key-value pairs (names) which I’ll later associate with the art. When the art piece/tile gets put on screen, I read its body info from the table and apply it. Basically, the newOutline() method has always been a “usually fine but not always perfect” approach… and that’s OK for many people, but I prefer making sure it’s perfect in every instance and I’ll take the extra effort to make sure it is.

Brent

Basically, the newOutline() method has always been a “usually fine but not always perfect” approach… and that’s OK for many people, but I prefer making sure it’s perfect in every instance and I’ll take the extra effort to make sure it is.

My point, though, is that in my example, the outline is not even remotely close to “fine but not always perfect”. The physics body doesn’t even cover a quarter of the shape even with a low courseness argument, which should be even finer. Whatever way newOutline calculates the vertices seems to be broken.

Does Corona intend to look into this?

Hi @jhow,

I see you filed a bug report on this, yes? If so, thanks, and now we have it on file, but I’m not sure how soon it will be prioritized among other bugs. Admittedly that API could use improvement, as the trace results can (but not always) vary widely.

Brent