2
votes

I am working on a Puzzle Bubble Type game in which I am making a body like this

FixtureDef  Fd =  PhysicsFactory.createFixtureDef(10f, 1f, 0.5f);
Body b  = PhysicsFactory.createCircleBody(mPhysicsWorld, gb, BodyType.DynamicBody, Fd);

This is a body of a ball, the ball reflects perfectly which it collides with left and right walls but when it collides with top wall it makes a weld joint with the top wall and its type is set to static, when another ball collides with the above mentioned ball they makes a weld joint with each other. Making joints are working very well but when two ballenter image description heres collides with each other or with the top wall there becomes a distance between them which is I think because of elasticity factor. I want NOT to have that distance I want to connect them in a way with no distance between them. Please note that collide connected factor of weld joint is set to true. I have also attached an image to clarify my question. I don't want distances between balls. I am unable to find solution for this problem please help.

1
Hi, I assume you are using a ContactListener to trigger your code upon collision, do you then run your code which sets the weld joints inside an Update thread? - I had a similar problem. For me this thread code executed after another update so the bubbles had a chance to move after the initial collision. I got around this by storing the body x and y positions as finals in the beginContact() interface method, then declare the update thread but let the first line move the body with a transform back to the final x and y positions you stored at the time of collision.Steven
I have tried this but no success on Collision I saved the position vector of a body and before making weld joint I transformed the body to that position vector. But it does nothing the body remains there. What I am doing wrong?Jawad Amjad

1 Answers

1
votes

I have found a solution. When bodies collide I set their restitution/elasticity to 0.

contact.getFixtureA().setRestitution(0);
contact.getFixtureB().setRestitution(0);

This solved my problem, lets see what problem can this method creates in future. Thanks for your help Steven