Variable number of vertices in physics POLYGON and CHAIN

You should really add a possibility I will explain in an example.

What we have now

myBody = physics.body( CHAIN, loop,
vec2(0,0),
vec2(10,5),
vec2(15,10) )

What we can’t do now, but is extremely easy for you to implement and is really important for dynamic games. I have no clue why you haven’t implemented such a possibility already.

a = {
vec2(0,0),
vec2(1,0),
vec2(1,5),
vec2(2,40),
vec2(0.5,10)
}

myBody = physics.body( CHAIN, loop, a )

For POLYGON and CHAIN.

If you do myBody = physics.body(CHAIN, loop, unpack(a) it will work

Yes, unpack() can return a bunch of variables that were in a table. If you look in the Physics Lab example you will see its use in function createRandPoly().

Also, the physics API is Box2D, a separate library developed by other people, so we can’t change it.

Oh, didn’t know there was such a thing as unpack(). Other languages I know well (c, c++, php, javascript) don’t have similar functionality (as far as I know at least). I like this feature of Lua though. As for “we can’t change that”, I guess, you probably can add that by using this unpack, but probably better just add an example with unpack into documentation. I looked into Phys Lab example, but didn’t find that unpack at the time I was searching for it. I’m pretty sure most people won’t as well.