Phys2D joint

Does any one have any idea on how I can have 2 shapes stick together so that if the object behind (a box) moves it will push the other (a circle) with their positions relative to eachother staying the same, at the moment I have tried using joints but the circle keeps rotating around the square when it moves.

NB: the world is a top down view, like the pool table demo

Thanks

You should be a little more specific about what needs to be accomplished. For example, do you need the sphere to stay touching the box when the box is pulled away, or have the sphere stop moving when the box stops as well. I would think a joint should accomplish this, maybe you just need stiffer joint parameters or a different type. Or you could try composite geometries acting as one physical object (I’m not sure if Phys2D can handle this, though, I never used it).

I need them to act as though they were glued together with super glue as in to act as a single body. So whatever the box does the circle will do.

Just an after thought. I suspect the solution would be to add some forces to counter those making it move around but thinking about physics is not a good idea for me as a few attempts I have made will prove. Any thoughts?

You mean something like :

scare = new Body( new Box(2*r,2*r), massScare );  // Create the scare (position 0,0)
circle = new Body(new Circle(r), massCircle);  // Create the circle
circle.setPosition( 2*r ,  0.0 ); // Put the circle on the scare

joint  = new FixedJoint(scare,circle);   // Attach the scare and the circle (fixed length and angle ?)

world.add(scare); // Add everything to the world
world.add(circle);
world.add(joint);

I had use something like that to joint several spheres (to apply forces on the side of a circle).

Hi,

You just need to use a FixedJoint, it’s easy. The only problem that I found with them is that if you the centres of two shapes are on the same point and you try to connect them with a fixed joint then they will not be fixed when you rotate one of them - they will spin around each other. The will however move up and down and across with each other.

Let us know if you get the FixedJoint working!
Keith

The results with the fixed joint are better than what I had before but still not perfect (namely vibration which can be annoying when the screen is scrolling), I’ll try and play around with things over the next few days and tell you guys how it worked out. Thanks for the help so far.