Hi there,
we developed a game which creates physic bodies with a dynamic amount of body parts.
Currently the solution is pretty pretentious. Our game can have physic objects with a total of 200+ Body elements. Depending on how many parts there are, we have serveral functions to create this objects.
This is how it lookslike:
if(partAmount == 0) then
physics.addBody(body,
{shape=bodyPart[0], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce}
);
elseif (partAmount == 1) then
physics.addBody(body,
{shape=bodyPart[0], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[1], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce}
);
elseif (partAmount == 2) then
physics.addBody(body,
{shape=bodyPart[0], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[1], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[2], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce}
);
elseif (partAmount == 3) then
physics.addBody(body,
{shape=bodyPart[0], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[1], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[2], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[3], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce}
);
elseif (partAmount == 4) then
physics.addBody(body,
{shape=bodyPart[0], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[1], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[2], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[3], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[4], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce}
);
ect…
My question: Would it be possible that you modify the physics.addBody function so it can build objects by using a table.
For example:
parts= {
{shape=bodyPart[0], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[1], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[2], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[3], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce},
{shape=bodyPart[4], filter=mFilter, density=dens, friction=mFriction, bounce=mBounce}}
}
physics.addBody(body, {parts})
This would be really helpfull and would save us alot (20k+ lines) of recurring code.
Thank you!
Amplexor