Question

I'm searching for a way to have a fixed joint between two bodies. I tried b2DistanceJointDef but it would still rotate. Use a constraint here? If so how?

Or better use b2PrismaticJointDef and retrict the movement?

My engine is cocos2d-js 3.0a2

Code:

        var jointDef = new b2DistanceJointDef();
        jointDef.length = 1.0;
        jointDef.frequency = 0.0;
        jointDef.dampingRatio = 0.0;
        jointDef.bodyA = body;
        jointDef.bodyB = lastBody;
        var joint = this.world.CreateJoint(jointDef);
Was it helpful?

Solution 2

I solved it using b2WeldJoint:

            var jointDef = new b2WeldJointDef();
            jointDef.referenceAngle = 0.0;
            jointDef.collideConnected = false;
            jointDef.bodyA = body;
            jointDef.bodyB = lastBody;
            jointDef.localAnchorA = body.tileOffset;
            jointDef.localAnchorB = lastBody.tileOffset;
            var joint = this.world.CreateJoint(jointDef);

OTHER TIPS

Unfortunately no joint is guaranteed to give a 100% fixed relation between two bodies. You could try the weld joint if it's available in that port, or as you suggest you could also try a prismatic or revolute joint, enable the motor with a very high force/torque value, and set the limits to the same value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top