physics.addBody multiple shapes - how?

I want to add multiple shapes to a physics object, that will have a varying number of facets.
For example, the object could be a star with a variable number of sides/points.
How do I dynamically create the physics detection shape for this?

with an object with a finite number of shapes (e.g 3) you can easily do:

physics.addBody( myStar, “static”,
{ density = 5, friction = 0.1, bounce = 0.6, shape={ 10,10,100,100 etc} }
{ density = 5, friction = 0.1, bounce = 0.6, shape={ 20,10,200,100 etc} }
{ density = 5, friction = 0.1, bounce = 0.6, shape={ 30,10,50,100 etc} }
)

but if the number of shapes is not known and will vary, how do I do it?

basically , this bit needs to repeat or be generated for each part.
{ density = 5, friction = 0.1, bounce = 0.6, shape={ 10,10,100,100 etc} }

I’ve tried various ways but not sure how to do this.
for next loop, concat string, another table etc, etc
Any ideas?
thx [import]uid: 49842 topic_id: 11321 reply_id: 311321[/import]

This should be in the Game Dev forum, but anyway, do yourself a favor and kick $20 bucks in for Physics Editor. I got it last week and it’s painfully simple to generate physics around odd shapes. It generates the lua code that you call with a couple of lines of your own code.

http://www.physicseditor.de/ [import]uid: 58455 topic_id: 11321 reply_id: 42131[/import]

thanks, but the question is about adding multiple shapes dynamically. Maybe its not clear.
Imagine I want to generate hollow polygons with a varying number of sides during the game.
Sure I could have a string of if then else statements to do the addbody statement, but I was looking for more elegant way.

I want to execute this line “shape={ 10,10,100,100 etc} }” a varying number of times depending on the number of lines the shape is constructed from- one shape for each line.
eg. if the body is constructed from 6 lines, then the “shape={ 10,10,100,100 etc} }” will be executed 6 times, once for each line.
[import]uid: 49842 topic_id: 11321 reply_id: 42135[/import]

Oops, sorry. Read it too fast.

The code the physics editor generates, however, may have the answer. It creates a static table of
these:

{ density = 5, friction = 0.1, bounce = 0.6, shape={ 10,10,100,100 etc} }  

And then unpacks and returns the contents of the table on the get call:

physics.addBody( shape, physicsData:get("objectname") )  

You would just have to create the table dynamically, but you could unpack it the same way for the addBody call.

Unpack info here:

http://www.lua.org/pil/5.1.html [import]uid: 58455 topic_id: 11321 reply_id: 42142[/import]

spot on davemikesell - thanks for that.
The unpack command does exactly what I need.
The wonders of lua :wink: [import]uid: 49842 topic_id: 11321 reply_id: 42297[/import]