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

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/

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.

Oops, sorry. Read it too fast.

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

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

spot on davemikesell - thanks for that.
The unpack command does exactly what I need.
The wonders of lua ;-)

views:1797 update:2011/10/5 21:23:48
corona forums © 2003-2011