Android Question how to create a Physics body inside another

noclass1980

Active Member
Licensed User
Longtime User
hi, I've come across a problem. My recent posts concerned the excellent Informatix's examples for libgdx which have bee solved. I now want to create a Body like a bottle and put some smaller bodies inside the bottle. So far, I create the bottle and small bodies ok and the small bodies fall into the open bottle. I now want to create the bodies inside the closed bottle but if i create the bottle and small bodies at the same position the small bodies are outside the bottle and so move away from the bottle as you would expect. How do I create bodies within a body so they are contained? Would a solution be to create the small bodies away from thbottle and the set a position within the bottles space? Hope this makes sense! Thanks in advance
 
Last edited:

noclass1980

Active Member
Licensed User
Longtime User
Thanks, I wondered if that was the case, I'll develop the plug approach. Should I attach the bottle and plug together with a weldjoint so they move togeted as a single body? So far the code i've figured out is

B4X:
Dim wj As lgBox2DWeldJointDef
Dim ancMV As lgMathVector2
wj.bodyA=Bodies
wj.bodyB=bdPlug
wj.localAnchorA=Bodies.getLocalPoint
wj.localAnchorB=Bodies.getLocalPoint
wj.referenceAngle=wj.bodyB.Angle-wj.bodyA.Angle
wj.collideConnected=True
ancMV=Bodies.getLocalPoint
wj.initialize(Bodies, bdTable,ancMV)
World.CreateJoint(wj)


but is this how I define ancMV? is it the position of the plug inside the top of the bottle? Thanks as always.
 
Last edited:
Upvote 0

Informatix

Expert
Licensed User
Longtime User
About Weld Joints, from the Box2D doc:

ancMV is the world anchor point of the two bodies.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User

ok, I stuck with my original requirement and eventually realised that the problem lay in the way I had constructed the PhysicSBodies. My original open bottle was a double skin but the closed bottle was only a single skin so effectively it was 100% solid with no space for the small bodies to go inside. Hence the immediate collisions as observed. The two attached pictures show what I mean.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…