Errors with newPolygonShape

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
LilaQ
Prole
Posts: 7
Joined: Mon Apr 30, 2012 9:45 pm

Errors with newPolygonShape

Post by LilaQ »

Hey there,

I'm having a hard time with the newPolygonShape function.

It keeps throwing me an error like "area > b2_epsilon", and don't quite know why.
I am trying to make an "L"-Shape.

This line here works without any problems (but lacks the last edge I need for the "L")

Code: Select all

love.physics.newPolygonShape(0,0,0,48,32,48,32,32,16,32)
But if I add the missing point like so:

Code: Select all

love.physics.newPolygonShape(0,0,0,48,32,48,32,32,16,32,16,0)
it will throw the error described above.

Any suggestions? Until now I made two single RectangleShapes and uses two fixtures to attach them to the body, but actually I don't think this is the best solution to this. So I wanted to rebuild my Shapes with the PolygonShape.

Would be great if any of you guys has an approach to this problem.

Thanks in advance

Edit:

Okay, I even tried to pass the vertices clockwise like:

Code: Select all

love.physics.newPolygonShape(0,0,16,0,16,32,32,32,32,48,0,48)
Now it does not throw any errors (for now), but this is not the shape I was looking for, it looks more like a chimney than an "L". I doublechecked my vertices, but I can not see any mistakes.

Any help?
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Errors with newPolygonShape

Post by ivan »

As far as I know, box2d accepts only 'convex' polygons (by default) with up to 8 vertices.
The shape L is concave.
LilaQ wrote:Any suggestions? Until now I made two single RectangleShapes and uses two fixtures to attach them to the body, but actually I don't think this is the best solution to this
From what I've found, it seems to be pretty efficient.

PS. The order of the vertices (I believe they have to be counter clockwise but I'm not 100%) is also important I think. A negative area of a shape suggests that your vertices may be ordered incorrectly.
LilaQ
Prole
Posts: 7
Joined: Mon Apr 30, 2012 9:45 pm

Re: Errors with newPolygonShape

Post by LilaQ »

Ah I see, I did not think of convex / concave polygons.

What would be more efficient, making two shapes, and adding them to the same body with two different fixtures OR making two body, each with one shape, each with one fixture, and then combine the two bodies with the newWeldJoint function?

Because I have some more bodies which run through some more rayCasts continuously and need to make things performing as good as possible.

Thanks for the help so far, ivan!
iemfi
Citizen
Posts: 52
Joined: Fri Mar 30, 2012 11:03 am

Re: Errors with newPolygonShape

Post by iemfi »

The problem with weld joints is that they're elastic. The two shapes will move around relative to each other. So unless you want that behaviour I think having 1 body is better.
LilaQ
Prole
Posts: 7
Joined: Mon Apr 30, 2012 9:45 pm

Re: Errors with newPolygonShape

Post by LilaQ »

That's what I suspected.

But the bodies with several shapes seem to occasionally collapse into each other, which does not happen with the single-shape bodies.

When this happens, it looks like, for example, that the long end of the first "L"-Body sits right between the edge of the long and the short side of the second "L"-Body. I hope you can imagine what I am talking about.

I am not sure if this only happens when the framerate drops too low while the objects move too fast, and (maybe) the frame where the collision would happen, is just being skipped.

Would like to hear your thoughts about this.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 50 guests