cocos2d-js: what is the best way to have a fixed joint between two bodies with box2d?

StackOverflow https://stackoverflow.com/questions/23416601

  •  13-07-2023
  •  | 
  •  

سؤال

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);
هل كانت مفيدة؟

المحلول 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);

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top