AnyPortrait > Forum > How to Use

Runtime IK sync from Unity 2D physics rig — SetBoneIK works but limb bending flips / pose diverges (World vs Self space?)

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1578
    botanbotan

      Hello AnyPortrait team/community,
      I’m trying to drive an AnyPortrait character from a Unity 2D physics rig (physics is master, AnyPortrait is slave). The portrait root follows correctly, and SetBoneIK affects the pose, but elbow/knee bending becomes unstable / flips, and the pose diverges significantly from the physics rig.

      Environment
      AnyPortrait: 1.6.2
      Unity: 2D (Rigidbody2D + joints), ragdoll-like physics rig
      Update timing: IK applied in LateUpdate()
      AnyPortrait setup (baked)
      Bones: Body, UpperArm_L/R, LowerArm_L/R, UpperLeg_L/R, LowerLeg_L/R
      IK target bones: Hand_L, Hand_R, Foot_L, Foot_R
      IK chains configured/baked so the arm/leg chains target Hand/Foot bones.

      Unity setup
      physics root: Rig_Body
      effectors: Eff_Hand_L/R, Eff_Foot_L/R (Transforms)
      Script moves apPortrait.transform to follow Rig_Body, then calls SetBoneIK for 4 limbs.
      Current script snippet (key part)

      // Called from LateUpdate()
      Vector3 targetPos = ToPortraitSpace(eff.position); // scale conversion
      bool ok = portrait.SetBoneIK(boneName, targetPos, Space.World, 1f, true);

      Notes:

      • I added ToPortraitSpace() because the portrait is scaled (e.g., 0.33) while the physics rig uses a different scale.
      • However, the API docs say Space.World is scene/world coordinates and Space.Self is apPortrait coordinates.
        So I’m not sure if my conversion + Space.World is incorrect.

      Symptoms

      • Root follow works (portrait moves/rotates with rig).
      • SetBoneIK returns true and the limbs move, but bending direction flips (elbow/knee) and pose becomes very different from the physics rig.
      • I suspect either:
      1. I’m passing coordinates in the wrong space (World vs Self), or
      2. I need recommended IK constraints / preferred angle settings to prevent flipping.

      Questions

      1. For SetBoneIK(boneName, position, Space.World/Space.Self, …), what is the recommended approach when the portrait is scaled relative to the physics rig?
        ・Should I pass eff.position directly with Space.World (no manual scale conversion), or
        ・Convert into portrait local coordinates and use Space.Self?
      2. What are best practices to prevent elbow/knee flipping when driving runtime IK every frame?
      3. Is LateUpdate() recommended, or should this be applied at a specific timing / execution order?

      Attachments 
      Play-mode screenshot showing the physics rig vs AnyPortrait pose mismatch (elbow/knee flipping)
      AnyPortrait editor screenshot showing bone hierarchy and IK chain targets (Hand/Foot)
      Unity Inspector screenshot showing script settings (bone names, effectors, follow rotation, etc.)

      Thank you for any guidance.

       

      #1579
      RainyRizzleRainyRizzle

        Hi!
        Sorry for the late reply.

        We reviewed your inquiry yesterday, and rather than simply providing answers to your questions, we felt it would be better to show you the entire implementation process.

        So, we’ve implemented a ragdoll using Physics2D in the current version, and we’re preparing an answer based on that.

        However, the implementation process and script are complex and require a lot of explanation, so we decided it would be better to add it to the official manual.

        We expect to have a manual on this topic ready within about two days.

        Thank you for your patience.
        We’ll add a comment to this post once the manual is complete.

        #1580
        botanbotan

          Thank you so much for your detailed response!

          I really appreciate that you went out of your way to implement and test the ragdoll yourself rather than just answering my question. I’ll wait for the manual and look forward to learning the correct implementation.

          Thank you again for your time and effort!

        Viewing 3 posts - 1 through 3 (of 3 total)
        • You must be logged in to reply to this topic.
        Scroll to Top