Hello,
I am trying to create a Pulley Joint between 2 circular balls. The problem is they are showing some very odd behavior .. They keep falling down (together) or continuously one keeps going up the other down and when the max Length is reached vice-verse happens 🙁
can anyone tell me what I am doing wrong .. Here is the code.
I am trying to create a Pulley Joint between 2 circular balls. The problem is they are showing some very odd behavior .. They keep falling down (together) or continuously one keeps going up the other down and when the max Length is reached vice-verse happens 🙁
can anyone tell me what I am doing wrong .. Here is the code.
Code:
CircleDef the_pivot = new CircleDef();
the_pivot.radius = ballRadius;
the_pivot.density = 0.3f;
//the_pivot.friction = 0.3f;
//the_pivot.restitution = 0.5f;
BodyDef bd = new BodyDef();
bd.position.set(new Vec2((float)12,(float)30));
Body body1 = world.createBody(bd);
body1.createShape(the_pivot);
body1.setMassFromShapes();
CircleDef the_pivot2 = new CircleDef();
the_pivot2.radius = ballRadius;
the_pivot2.density = 0.6f;
//the_pivot2.friction = 0.3f;
//the_pivot2.restitution = 0.5f;
BodyDef bd2 = new BodyDef();
bd2.position.set(new Vec2((float)22,(float)30));
Body body2 = world.createBody(bd2);
body2.createShape(the_pivot2);
body2.setMassFromShapes();
//Code for creating the Pulley System
Vec2 anchor1 = body1.getWorldCenter();
Vec2 anchor2 = body2.getWorldCenter();
Vec2 groundAnchor1 = new Vec2(anchor1.x, anchor1.y - 10f);
Vec2 groundAnchor2 = new Vec2(anchor2.x, anchor2.y - 10f);
float Number = 1f;
PulleyJointDef pulleyJointDef = new PulleyJointDef();
pulleyJointDef.initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, Number);
//Make sure the maxLength is greater than the distance between the body centre and its groundAnchor
//otherwise there will be no movement in the Y direction as the rope size has been restricted.
pulleyJointDef.maxLength1 = 30;
pulleyJointDef.maxLength2 = 30;
m_joint1 = (PulleyJoint)world.createJoint(pulleyJointDef);
the_pivot.radius = ballRadius;
the_pivot.density = 0.3f;
//the_pivot.friction = 0.3f;
//the_pivot.restitution = 0.5f;
BodyDef bd = new BodyDef();
bd.position.set(new Vec2((float)12,(float)30));
Body body1 = world.createBody(bd);
body1.createShape(the_pivot);
body1.setMassFromShapes();
CircleDef the_pivot2 = new CircleDef();
the_pivot2.radius = ballRadius;
the_pivot2.density = 0.6f;
//the_pivot2.friction = 0.3f;
//the_pivot2.restitution = 0.5f;
BodyDef bd2 = new BodyDef();
bd2.position.set(new Vec2((float)22,(float)30));
Body body2 = world.createBody(bd2);
body2.createShape(the_pivot2);
body2.setMassFromShapes();
//Code for creating the Pulley System
Vec2 anchor1 = body1.getWorldCenter();
Vec2 anchor2 = body2.getWorldCenter();
Vec2 groundAnchor1 = new Vec2(anchor1.x, anchor1.y - 10f);
Vec2 groundAnchor2 = new Vec2(anchor2.x, anchor2.y - 10f);
float Number = 1f;
PulleyJointDef pulleyJointDef = new PulleyJointDef();
pulleyJointDef.initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, Number);
//Make sure the maxLength is greater than the distance between the body centre and its groundAnchor
//otherwise there will be no movement in the Y direction as the rope size has been restricted.
pulleyJointDef.maxLength1 = 30;
pulleyJointDef.maxLength2 = 30;
m_joint1 = (PulleyJoint)world.createJoint(pulleyJointDef);