Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to move an existing chain and target? #1

Open
cykoder opened this issue May 14, 2022 · 0 comments
Open

How to move an existing chain and target? #1

cykoder opened this issue May 14, 2022 · 0 comments

Comments

@cykoder
Copy link

cykoder commented May 14, 2022

Hello!

I have been trying to implement this library, I have it working if I re-create the chain/bones each frame. However, trying to preserve the structure, chain3d etc I get some weird results...

  createIKStructure() {
    const segment = this.segment;
    this.ikLegTarget = new IK.V3(this.footPosition.x, this.footPosition.y, this.footPosition.z); // or IK.V2
    this.ikLeg = new IK.Chain3D(); // or Chain2D
    this.ikLeg.setFixedBaseMode(true);
    const leg = this.ikLeg; // or Chain2D
    // with start position, direction and length:
    const baseBoneA = new IK.Bone3D( // or Bone2D
        new IK.V3(segment.x, segment.y, segment.z), // start position. Use IK.V2 if you are using Chain2D.
        undefined,          // no end position given
        new IK.V3(0, 1, 0), // direction. Use IK.V2 if you are using Chain2D.
        1                   // length
    );
    leg.addBone(baseBoneA);
    leg.addConsecutiveBone(
        new IK.V3(0, -1, 0), // direction. Use IK.V2 if you are using Chain2D.
        1               // length
    );
    this.structure = new IK.Structure3D(); // or Structure2D
    this.structure.add(leg, this.ikLegTarget);
  }

  update(delta) {
    this.createIKStructure(); // only works if i do this, below lines seem to do nothing/produce buggy results
    leg.baseLocation.set(segment.x, segment.y, segment.z);

    this.ikLegTarget.set(this.footPosition.x, this.footPosition.y, this.footPosition.z); // or IK.V2

    this.structure.update();
  }

As you can see from this rough snippet, I tried using a few methods to reset the base location and others. Doesnt seem to do much besides produce buggy results. Re-creating everything produces the correct result from what I can see. Any ideas how to approach this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant