Birch-san / box2d-wasm

Box2D physics engine compiled to WebAssembly. Supports TypeScript and ES modules.
265 stars 21 forks source link

Unable to use SetLength() with DistanceJoint #52

Closed V-HuangChunMing closed 2 years ago

V-HuangChunMing commented 2 years ago

when i want to set length dynamicly , i find that either bodyA and bodyB transform have no changes.also the anchor and localanchor. the only change is length. I think there may something wrong or my code has bugs?

  setDistanceJoint(config: {
    jointId: string,
    length: number,
  }) {
    const joint = <Box2D.b2DistanceJoint>this.checkJoint(config.jointId)?.b2Joint
    if (joint) {
      joint.SetLength(config.length); 
      // console.log(joint.GetLength());
      // console.log(joint.GetStiffness());
      console.log(joint.GetAnchorA())
      console.log(joint.GetAnchorB())
      // console.log(joint.GetReactionForce(1));
      // console.log(joint.GetReactionTorque(1));
      // console.log(joint.SetMinLength(config.length));
    }
  }
V-HuangChunMing commented 2 years ago

you mast set minLength and maxLength when you wants to use and not init with length