Bezier Curves Physics and Ghost Vertices

I’ve been done plenty of testing and research with Level Director and bezier curves.

I have some bezier curves (nothing extreme, just some nice hills up and down).

I have a rectangle that slides up and down the hills.

The problem is that occasionally the corner of the rectangle gets stuck and flips the rectangle (not desired effect).  

Digging into the function in the Level Editor helper file I can see that the curve is split into segments and little overlapping long-triangles are created (sort of like a sawtooth).  This is still causing flipping at certain points and it’s also horrible because the object can’t go backwards over the curve.

Doing some more research I’ve learned that this is a common issue/question with Box2d and with ghost vertices.

http://www.iforce2d.net/b2dtut/ghost-vertices

The thing that’s cool is that the chain shape in Box2d removes this issue:  http://www.box2d.org/manual.html

In section 4.6 it says this:   “Chain shapes automatically eliminate ghost collisions and provide two sided collision.”

Is this the same as the 

Edge Shape (Chain) Body

Listed here in Corona docs:  http://docs.coronalabs.com/guide/physics/physicsBodies/index.html

Is there anyway that Level Director’s algorithm could be upgraded to use this for bezier curved physics?  I think it would improve the overall result of physics applied to bezier curves.

Yes it was quite a challenge getting the Bezier curves working and even more difficult when you add physics to the equation.

It has actually been on my list for a while to revisit the Bezier curve creation as I always felt there was a better way to implement it but back then (approx. 2 years ago) my Lua skills were limited and this was also prior to Graphics 2.0.

I’ll try and find some time to take a look at this.

Great!

I’ll do more digging and research as well.  

I had a play today and think I may have a solution.

The revised code is actually 50% faster and uses chain edge physics.

I’ll send you the new file to test.

FYI - if you set the physics shape on your object to be a circle or a shape similar to a rounded rectangle this also helps eliminate the problem.

Hopefully the new changes I sent will work but I’m a little concerned about the 32 vertices limit on chain edges as it appears to work with more than 32 in the simulator.

Yeah I tried rounding the corners of the shape but it would still snag.

I looking into using a circle but that doesn’t work because I can’t offset the circle shape on the object (a long rectangle) so it would be in the center which won’t work for what I’m trying to achieve.

I’m also curious about the 32 vertices limit and wonder if it’s a Corona limit (I couldn’t find any mention of a 32 vertices limit in box2d documentation). 

Yes fingers crossed as it seems to work really well in my initial tests.

I’ve only tested it on one device (a 3 year old Android phone) and it seems to work fine.  

In my test I had 4 bezier curves to create a longer level and it had no problems.  Thanks for the quick turn-around on this.  I’ll let you know if I have any issues. 

Sounds good, glad to help.

If any other Level Director users would like to try out the new Bezier code then let me know. 

Hi everybody

Yes I would be very interested about your code.
I am struggling to do the following (please open the attachment):
 

Please have a look at the pic.

For a bouncing ball on a bezier curver I would like to dynamically calculate the absolute distance between the anchor point of the ball and the corresponding coordinate on the bezier curve at any given x while the result is the distance in pixels of y.

The requirement would be that at any given x one could calculate the corresponding coordinates on the bezier curve.

Do you think that it is possible and does anyone have an idea how to do it?

Thanks for any reply

Matteo

Hi, sorry for the delay.

You can get the latest helper file from here : http://bit.ly/1OLni8F

By default this will use Chain physics for Bezier curves.

Let me know how you get on.

Hi how can I get the distance betwen the bouncing ball and the corresponding point on the bezier curve with same x-coordinate?

Yes it was quite a challenge getting the Bezier curves working and even more difficult when you add physics to the equation.

It has actually been on my list for a while to revisit the Bezier curve creation as I always felt there was a better way to implement it but back then (approx. 2 years ago) my Lua skills were limited and this was also prior to Graphics 2.0.

I’ll try and find some time to take a look at this.

Great!

I’ll do more digging and research as well.  

I had a play today and think I may have a solution.

The revised code is actually 50% faster and uses chain edge physics.

I’ll send you the new file to test.

FYI - if you set the physics shape on your object to be a circle or a shape similar to a rounded rectangle this also helps eliminate the problem.

Hopefully the new changes I sent will work but I’m a little concerned about the 32 vertices limit on chain edges as it appears to work with more than 32 in the simulator.

Yeah I tried rounding the corners of the shape but it would still snag.

I looking into using a circle but that doesn’t work because I can’t offset the circle shape on the object (a long rectangle) so it would be in the center which won’t work for what I’m trying to achieve.

I’m also curious about the 32 vertices limit and wonder if it’s a Corona limit (I couldn’t find any mention of a 32 vertices limit in box2d documentation). 

Yes fingers crossed as it seems to work really well in my initial tests.

I’ve only tested it on one device (a 3 year old Android phone) and it seems to work fine.  

In my test I had 4 bezier curves to create a longer level and it had no problems.  Thanks for the quick turn-around on this.  I’ll let you know if I have any issues. 

Sounds good, glad to help.

If any other Level Director users would like to try out the new Bezier code then let me know.