Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

FINAL IK - Full Body IK, Aim, Look At, FABRIK, CCD IK... [1.0 RELEASED]

Discussion in 'Assets and Asset Store' started by Partel-Lang, Jan 15, 2014.

  1. florianBrn

    florianBrn

    Joined:
    Jul 31, 2019
    Posts:
    53
    Hey,
    How can I know when a foot touches the ground using GrounderFBBIK? There doesn't seem to be any event I could register to in order to get a callback when that happens.
    Thanks!
     
  2. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    Grounder actually has no idea if a foot is touching the ground. It basically just offsets the feet to maintain their animated height over uneven ground surface.

    If you want to do footstep sound FX, you should add events to all the locomotion animation clips in the animation import settings, make a script that plays the SFX when those events are called.

    Best,
    Pärtel
     
  3. Eman_resu

    Eman_resu

    Joined:
    Nov 26, 2019
    Posts:
    9
    Hi, is there a way to limit the movement of the charactercontroller based on the stretching of FullBodyBipedIk? My intention is to attack my hand when he goes into contact with the door, so that he can open it by carrying it with him. Thanks!
    finalikdoor.png
     
  4. jamiedixxon

    jamiedixxon

    Joined:
    Mar 20, 2018
    Posts:
    8
    Is there a way to animate the LegIK parameters? I have a character that strikes poses that require a longer solution (1.5) but during the rest of the animation setting to 1 gives the best results. When trying to attach an animation to the LegIK node I only see "enabled" and "fix transforms".

    Screen Shot 2022-11-16 at 12.15.34 PM.png
     
  5. Michal_Stangel

    Michal_Stangel

    Joined:
    Apr 17, 2017
    Posts:
    151
    Hi Pärtel,

    Occasionally happens to me that script IKSolverTrigonometric triggers console message "Look rotation viewing vector is sero". And because it fires hundreds of these varnings per second, it almost freeze editor.
    Could you please add some check to these two lines of code (enclosed)?
     

    Attached Files:

  6. Eman_resu

    Eman_resu

    Joined:
    Nov 26, 2019
    Posts:
    9
    Hi! Is it possible to soften the interpolation between an interaction trigger and the other? possibly adding an intermediate target to give it a curve between one pose and another... Thanks https://imgur.com/zc4tyCX
     
    Last edited: Nov 18, 2022
  7. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    You could just give it a max range like:

    Code (CSharp):
    1. Vector3 v = character.position - obj.position;
    2. v.y = 0f;
    3. float mag = v.magnitude;
    4. if (mag > allowedRange) character.position = new Vector3(obj.position.x, character.position.y, obj.position.z) + (v / mag) * allowedRange;
    Unity can't animate variables in nested classes. You'd have to make a wrapper for it like:

    Code (CSharp):
    1. public LegIK legIK;
    2.  
    3.     [Range(0f, 1f)] public float positionWeight;
    4.     [Range(0f, 1f)] public float rotationWeight;
    5.  
    6.     void OnDidApplyAnimationProperties()
    7.     {
    8.         legIK.solver.leg.positionWeight = positionWeight;
    9.         legIK.solver.leg.rotationWeight = rotationWeight;
    10.     }
    OnDidApplyAnimationProperties is an undocumented monobehaviour callback, but it actually works.

    Hey,
    Could it be that one of the bones used by the IK has 0 length, I mean the position of 1 bone is the same as the next?

    Hey,
    You should use just a single interaction object for that door. Make an animation that animates the hand target from position A to B instead of switching between multiple interaction objects for the same door.

    Best,
    Pärtel
     
    Whatever560 and Eman_resu like this.
  8. Michal_Stangel

    Michal_Stangel

    Joined:
    Apr 17, 2017
    Posts:
    151
    It's possible. Happens only sometimes after I load saved game with many different characters. So it's difficult to know what's wrong.
     
  9. GoldFireStudios

    GoldFireStudios

    Joined:
    Nov 21, 2018
    Posts:
    160
    I've got a non-biped robot that only has arms with IK applies to them. It can sometimes come in contact with the ground, and I'd like to prevent the arms from clipping through the ground. I figured I could achieve this by adding a collider and rigid body to the hands, but this doesn't work as I assume the IK is just overriding the physics.

    I don't need full active ragdoll physics for this character as that seems like it would be overkill. I suppose worst-case I can raycast to the ground and then pin effectors for each hand to that location, but it seems like an actual physics collision would look best if possible. Is there a method I'm overlooking to achieve this effect where the hand colliders can interact with the terrain or another physics object while maintaining the IK on the arms?

     
  10. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    You can mix animation, IK and physics, but only with the help of the PuppetMaster asset. That allows you to blend between animation and ragdoll, have the arms unpinned from the animation so they'd be actuated only by the muscles (joints with slerp drive basically).

    But you could also use GrounderIK (like the Bot example in the Grounder demo) because those arms look like they could just as well be legs. Grounder does foot placement correction, warping animation to the uneven game terrain basically.

    I could add Vector3.zero checks there, but it would just hide the real problem (of bones having zero length).
    If you temporarily change Initiate to this>

    Code (CSharp):
    1. public void Initiate(Vector3 childPosition, Vector3 bendNormal) {
    2.                 if (childPosition == transform.position)
    3.                 {
    4.                     Debug.LogError("IKSolverTrigonometric has a zero bone length. Bone name: " + transform.name, transform);
    5.                     Debug.Break();
    6.                 }
    7.  
    8.                 // Get default target rotation that looks at child position with bendNormal as up
    9.                 Quaternion defaultTargetRotation = Quaternion.LookRotation(childPosition - transform.position, bendNormal);
    10.                
    11.                 // Covert default target rotation to local space
    12.                 targetToLocalSpace = QuaTools.RotationToLocalSpace(transform.rotation, defaultTargetRotation);
    13.                
    14.                 defaultLocalBendNormal = Quaternion.Inverse(transform.rotation) * bendNormal;
    15.             }
    Then it will pause the game if it finds the problem and log out the name of the bone. Click on the error message and it will select that bone and then you can see why its position matches with the next bone's position. Maybe the characters are scaled up from zero as they spawn?

    Best,
    Pärtel
     
  11. MeteTurkay

    MeteTurkay

    Joined:
    Nov 10, 2022
    Posts:
    10
    Hi @Partel-Lang !
    Lets say my player holding a steer as interaction object with interaction target, how can i smoothly change interaction of hand between handbrake and gear? I did add interaction object to handbrake and gear as well, player holds it nice but it starts from base position of poser, not from holding steer position, what should i do for starting from currently holding objects position?

    Edit for more info;
    Basically, while im steering i want to smoothly change my hand position between car parts. when i press handbrake button while my hand holds steer interaction object, hand goes default position and then handbrake, i want to switch between directly from steer to gear, gear to handbrake etc. Thank you for your amazing asset, cheers!
     
    Last edited: Nov 28, 2022
  12. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,491
    Just a heads-up, I was getting a console error "Tag is empty" when trying to call InteractionObject.GetTarget() [2021.3.14f]. This error likely shows up whether the InteractionSystem has a tag or not, but in my case I don't use them.

    To check for the absense of a tag, it seems fine to just read the .tag. To check for a specific match with a user-specified string, you should definitely use CompareTag().

    My patch:

    Code (CSharp):
    1.         public InteractionTarget GetTarget(FullBodyBipedEffector effectorType, InteractionSystem interactionSystem) {
    2.             //if (interactionSystem.CompareTag(string.Empty) || interactionSystem.CompareTag("")) {
    3.             if (string.IsNullOrEmpty(interactionSystem.tag)) {
    4.  
    Unity is kind of schizophrenic about tags and tag comparisons. On the one hand, having a registered-tag system can benefit from optimizations and avoid typos, on the other hand, it doesn't well deal with checking the absense of a tag.
     
  13. billygamesinc

    billygamesinc

    Joined:
    Dec 5, 2020
    Posts:
    345
    I installed puppetmaster today and ran into some issues. When finalIK is present, all shared assets must be unchecked. I did that but I think it messed up some of the physics.
    Some of the demos cause the character to fall through the ground immediately upon movement.
    Characters ragdolling right after their animation in certain test demos such as Puppet RaycastHit.

    I also have a question about PuppetMaster's raycast hit. How would I be able to make it simulate the Punching demo where the force simulation is applied but the character stays pinned? I messed with all the parameters but no matter what the raycasthit causes it to become ragdoll
     
  14. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,491
    I was trying to read the curves in my animation-based hand-posing solution, and found this quirk of the InteractionSystem API.

    * The InteractionSystem.GetProgress() returns the progress (normalized 0~1) along the set of curves.
    * The InteractionObject.GetValue() takes a timer which is non-normalized time from 0 at the start of the interaction.
    * There is no public GetLength() or GetTime() to bridge that gap. If I want the curve value. I have to keep track of my own timer += Time.deltaTime during the interaction. I only noticed this once I used a curve that was longer than 1f seconds.

    I don't need a patch, but it's a really minor thing to think about improving sometime.
     
  15. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    Thanks for the heads-up, will add that change in.

    There is InteractionObject.length that you can use. Gives you the length of the interaction (the time value of the last key of the longest curve).

    Hey,
    When you import PM to an existing project that has Layer Collision Matrix changed, might be that some of the demos don't work because of some layers not having collisions between them.

    About having the puppet never lose balance, if you set behaviourPuppet.knockOutDistance to Mathf.Infinity in Start, it will never get knocked out.

    Best,
    Pärtel
     
  16. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,491
    I could have sworn that was private/protected when I looked, but I guess not. Thanks.
     
  17. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    it's just public get, private set

    Cheers
     
  18. BrianDuffyGames

    BrianDuffyGames

    Joined:
    Sep 16, 2018
    Posts:
    9
    I am currently getting this same null reference error when a second player enters the room, I've updated the Oculus XR Plugin and reimported the Oculus integration package and neither has fixed the problem. Anyone got any suggestions?

    I didn't have the error a few weeks ago, and I feel like I've checked off the obvious solutions.
     
  19. MeteTurkay

    MeteTurkay

    Joined:
    Nov 10, 2022
    Posts:
    10
    Hi! When i interact with something with interaction system should i add hand posture(interaction target) on interaction object for every different player model? Because i changed my player model and hand posture got weird. Is there anything i can do? Cheers.
     
    Last edited: Dec 8, 2022
  20. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    119
    Hi Partel-Lang! I have a general question for you.

    I have a character with a floating capsule collider where, whenever my character collides with an overhead obstacle, it gets pushed down. This causes an undesired effect of the mesh's feet visually sinking into the ground, until the bottom of its collider finally contacts the ground.



    Is there a way to use Final IK to, instead, make the feet appear to stay planted on the ground but the knees bend? If so, how would you do this? I barely understand IK at all, but someone told me this solution might be possible with IK. And I have no idea how to begin!
    Thanks either way.
     
  21. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    No idea.. what does that line 2120 say in your version of OVRManager.cs?

    Hey,
    You only need to add new hand poses to the interaction objects if the bone orientations of the character hands are different. If you need both characters to still be able to use the interactions, you'll have to use tags. Set "Target Tag" in Interaction System component like "Character A" and "Character B", then tag the InteractionTargets accordingly.

    Hey,
    First, you'll need to know where the ground level actually is, can do that with raycasting. Then you'll need 2x LimbIK components, set them up for the legs.
    In LateUpdate, calculate the Y correction:
    Code (CSharp):
    1. float y = raycastHitPoint.y - character.y;
    Then just set limb IK target position like this:
    Code (CSharp):
    1. leftFootIK.solver.IKPosition = leftFootIK.bone3.transform.position + Vector3.up * y;
    That'll raise the feet to ground level.

    Best,
    Pärtel
     
    ml785 likes this.
  22. ml785

    ml785

    Joined:
    Dec 20, 2018
    Posts:
    119
    @Partel-Lang That worked! INCREDIBLE tool!! Thanks so much!!!!
     
    Partel-Lang likes this.
  23. YuriyVotintsev

    YuriyVotintsev

    Joined:
    Jun 11, 2013
    Posts:
    93
    Hi, I need to manualy update VRIK with animated locomotion. How i can achieve this? For now i am disabling Animator and execute this code every frame:

    Code (CSharp):
    1.     private void UpdateVRIK()
    2.     {
    3.         Animator.Update(Time.deltaTime);
    4.         VRIK.solver.FixTransforms();
    5.         VRIK.UpdateSolverExternal();
    6.     }
    But it looks terrible.

    (Since i am updating Animator with Update method i commented check for enabled animator in locomotion code)
     
  24. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,

    Animator.Update(Time.deltaTime);
    VRIK.solver.Update();

    Make sure to disable VRIK component in Start. Don't need FixTransforms if you only call solver.Update together with Animator.Update.

    Best,
    Pärtel
     
  25. retired_unity_saga

    retired_unity_saga

    Joined:
    Sep 17, 2016
    Posts:
    290
    dev, Mr. Partel-Lang, hello!! I had a crazy idea!

    I love umotion, and other similar editors, but they are a huge pain sometimes for setting up custom IK rigs and making use just to iterate new animations

    what if you made a Final IK Animation asset or addon so we can get IK results, in editor, during animation, if you make it additive maybe we can support other animation tools or something, idk

    basically,

    im.. wishing for a way to enable Final IK mechanics outside of play mode...

    thanks again!
     
  26. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    I really wish I had the time to do something like that. I've actually got a WIP solution and lots of ideas, but zero time to push it forward. Already pretty swamped with supporting FIK and PM.

    Cheers
    Pärtel
     
    retired_unity_saga likes this.
  27. rogerterheide

    rogerterheide

    Joined:
    Feb 15, 2017
    Posts:
    1
    Hi Partel,

    We have been using VRIK for a while, and it's really such a great tool.
    We are currently using it with multiple trackers for NPC characters.
    I was running into a problem with the EditorIK that says:
    'Start Solver' disabled for invalid solver setup

    Would you know why that is and could help?
    upload_2023-1-2_12-42-9.png

    Thanks in advance,
    Nikita
     
  28. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    Please grab this patch, then it should give you a more useful message about what the problem is.

    Best,
    Pärtel
     
  29. volkerror

    volkerror

    Joined:
    Apr 5, 2018
    Posts:
    16
    Hey Pärtel,

    I've bought FinalIK a few years ago (and was very impressed by it then), then sadly had to stop working with Unity altogether because of a lack of spare time. Now I've started again for a quite few month, learned this and that and ... well ... I am even more impressed. :)

    The reason I'm writing this right now: In the last few days one thing happened three times in a row. I thought: "Oh, adding *this* feature would be a nice way to integrate FinalIK into my current project" (e.g. a controller for the AimIK-script that does a raycast sphere and switches the aim (the head in my case) to the nearest target). Then I sat there and coded a happy few hours, had somewhat of a success and finally ... found out that whatever I had worked on, you already did. Just better, slicker and easier to use. In the given example I now scrapped everything I myself did and just do a raycast and pass the nearest collider.transform to your AimIK controller script as the target. :D

    So on the one hand I do feel stupid, as I do so often when learning to code as an old man, but on the other hand I am very, very grateful for your superb work. So I guess, this post is nothing more than a really big THANK YOU!

    Cheers,
    Volker
     
  30. SammmZ

    SammmZ

    Joined:
    Aug 13, 2014
    Posts:
    174


    Hey! I'm trying to make some kind of a foot-roll but I'm unsure if it's possible and what modules I need. In particular, I want FBIK to control the position of the _foot bone but instead of moving all the foot hierarchy with the foot controller, I need a _toe bone to remain its position and rotation. Is it possible and what kind of setup do I need for this?
     
  31. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Hey Pärtel-Lang.
    First of, thank you so much for this amazing features of final ik. I am mainly using the biped ik and I am very happy with it.
    Recently, I came a cross a problem with the ik of the spine. I saw you are using FABRIK for it. It works well for placing the chest to a specific position. However, I would like to use rotations to alter the spine for more convenience. Something like a SplineIK. This is demonstrated in the following video section (At 9m: 48s in the video, second example) ...



    Is such a spine possible to rig with final ik? If not could you give me a hint on how to implement it.

    Thank you very much for your help!
    Have a good day :)
     
    Last edited: Jan 13, 2023
  32. claudius_I

    claudius_I

    Joined:
    May 28, 2017
    Posts:
    254
    Hello, why can be happen this?

    Thanks

    Claudio
     

    Attached Files:

  33. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey, thank you so much for stopping by just to say that, much appreciated! :)

    Hey,

    Not with FBBIK, but can be done with VRIK, that lets you assign toe bones to the solver and use them as the target.
    Or LegIK, which is basically the same VRIK leg solver.

    Hey,
    I don't have a solver like that, sorry. With FBBIK you can use the OffsetEffector (see the "Offset Effector") demo to do something similar. Also, if you need to do something simple like just bend the spine left/right, you could add some euler offset to each spine bone's localRotation in LateUpdate.

    Hey,
    Do you maybe have Grounder used there? That can move the pelvis, offsetting the solution for the hand.
    What's your IK setup look like?

    Best,
    Pärtel
     
  34. SammmZ

    SammmZ

    Joined:
    Aug 13, 2014
    Posts:
    174
    Oh, I see! Never touched that "new" stuff, I was always the old-school FFBIK/Limb enjoyer :D
    I assume VRIK and LegIK didn't have Playmaker support?
     
  35. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    111
    Hey Pärtel,
    thank you for your quick response. Controlling the spine using a spline based solver is very convenient in my opinion. Therefore, I tried to implement this solver, and it turned out working well. The spine position and rotation can be controlled using a start (=pelvis) and target (=chest) handle. I attach the source code (MIT-0) for everyone else to use, feel free to add it to your FinalIK if you want. It is based on the bezier spline, implemented by catlikecoding (see here, MIT-0). I added support for twisting the spline using a technique called swing-twist decomposition (see here). The implementation inherits the IKSolver class and is therefore easy to integrate, e.g. in BipedIK. You should change the variables boneUp, boneForward, startUp, targetUp accordingly.

    Thanks to the well organized code of FinalIk, it was fun and straight forward to code the custom solver. Your work on FinalIk is really impressive.

    Have a nice day!
     

    Attached Files:

    Partel-Lang likes this.
  36. brokenspiralstudios

    brokenspiralstudios

    Joined:
    Oct 20, 2021
    Posts:
    45
    Hello, I have successfully completed the Interaction System Part 1 for Final IK and am able to pickup an object. However after picking up the object, because it now parents to the character's hand, the rotation changes. How do I maintain the rotation when the object is first picked up? Normally how I've done it in the past is to make the object a child of a "Object Holder" transform that I can then adjust during runtime and then copy the component. Thanks
     
  37. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    725
    I'm using IK to adjust an animation. I'd like to figure out the position the hand would be in without IK, then use the difference between that and the target (in local space) to compute a correction.

    I'm having trouble getting that original position. I tried grabbing it in Update(), but that just winds up giving me the last frame's post-IK position. This surprised me a little, since I swore that would give me the original animated position!

    Anyway, I did get it working by inserting myself into the solver process:

    Code (CSharp):
    1. var oldDelegate = bodyIK.solver.OnPreRead;
    2.  
    3.         bodyIK.solver.OnPreRead = () => {
    4.             var newPos = animator.GetBoneTransform(HumanBodyBones.RightHand).position;
    5.  
    6.         [...]
    ...but is there a nicer way to do this? :)
     
  38. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    There are VRIK Playmaker actions if you have the latest (2.2) version of FIK. Package in the "Plugins/RootMotion/FinalIK/_Integration" folder.

    Oh, glad you figured it out! Can't add it to FIK (for legal S***) but if anyone asks for the same thing, will point to it. Thank you so much for sharing!

    Hey,
    Can't see that happening here, how to reproduce this issue? Could you record a video or send some kind of a repro package or instructions?

    You could also add a UnityEvent to the the pick up event, that calls a function in a script that sets the object's rotation to what you need it to be.

    Hey,
    Animation is updated between Update and LateUpdate, Final IK components normally update in LateUpdate, but after your own scripts' LateUpdates because FIK components have a very high value in the Script Execution Order.
    So to read the animated position of the hand before IK has been applied, just read it from LateUpdate.

    Best,
    Pärtel
     
  39. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    4,383
    I've had FinalIK for 6 years now and never used it. Just now realized that mistake. It's so easy to set up with very stunning results :)


    Excellent asset!
     
  40. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Oh, wow, that werewolf is awesome! Thanks for sharing! :)
     
    Rowlan likes this.
  41. omanuke

    omanuke

    Joined:
    May 5, 2017
    Posts:
    30
    Hi,
    Is it possible control body IK by changing the position and the rotation of forearm?
    Suppose the situation that one character hold other character's forearm and move it around. Other player should walk front or back if his forearm is pulled or pushed strongly.
     
  42. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    I don't have any solver that can do that, sorry. FBBIK doesn't have an effector for the forearm. Can just hold from the hand like in the "Holding Hands" demo. With PuppetMaster you could create a fixed joint between the hand and the forearm and loosen the upper body pin weights of the puppet to be able to push/pull it a bit, use animation for taking steps back/forward.

    Best,
    Pärtel
     
  43. omanuke

    omanuke

    Joined:
    May 5, 2017
    Posts:
    30
    Hmmm...
    I'm not familiar with PuppetMaster.I'll check it.
    Could I use PuppetMaster and FinalIK together? Or they are completely different system?
     
  44. halley

    halley

    Joined:
    Aug 26, 2013
    Posts:
    2,491
    From the Inspector, the LookAtIK component has a list of transforms that make up the part of the spine that should twist.

    However, I can't quite figure out how to populate this list from a script. The inheritance and inner classes are not obvious. I'm trying to make an auto-configure tool because I have a bunch of different characters with different avatars, but I can look them up with the bone names.

    Code (CSharp):
    1.             LookAtIK ik = GetComponent<LookAtIK>();
    2.             ik.solver.head.transform = info.head;
    3.             List<Transform> spine = new List<Transform>();
    4.             string[] bones = { "Neck", "UpperChest", "Chest" };
    5.             foreach (string bone in bones)
    6.                 if (myAvatarLookupClass.HasMixamoBone(bone))
    7.                     spine.Add(myAvatarLookupClass.GetMixamoBone(bone));
    8.             ik.solver.spine = new IKSolverLookAt.LookAtBone[spine.Count];
    9.             for (int i = 0; i < spine.Count; i++)
    10.                 ik.solver.spine[i] = new IKSolverLookAt.LookAtBone(spine[i]);
    Edit: Looks like this works.
     
    Last edited: Feb 7, 2023
  45. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    538
    For this issue, can I call the solver Update in StateIK (As it seems the Constraint is updated in a PreLateUpdate state that would occur after IK) ? I tried this, but it does not seem to work. The script does retrieve my FBBIK and goes into OnStateIK but then the character is either disappearing from one frame to the other or the grounder is not working.
    I based my logic on the unity comment here : https://issuetracker.unity3d.com/is...-function-does-not-yield-the-correct-position

    Code (CSharp):
    1.     /// <summary>
    2.     /// Updates <see cref="SolverManager"/> manually at the end of the <see cref="OnStateIK"/> pass. This to enable constraints.
    3.     /// </summary>
    4.     [DefaultExecutionOrder(20000)]
    5.     public class IKStatePreLateUpdater : StateMachineBehaviour
    6.     {
    7.         private List<IK> _solvers;
    8.  
    9.         public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    10.         {
    11.             base.OnStateUpdate(animator, stateInfo, layerIndex);
    12.             foreach (var solverManager in _solvers)
    13.             {
    14.                 solverManager.GetIKSolver().FixTransforms();
    15.             }
    16.         }
    17.  
    18.         public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    19.         {
    20.             base.OnStateIK(animator, stateInfo, layerIndex);
    21.             foreach (var solverManager in _solvers)
    22.             {
    23.                 solverManager.GetIKSolver().Update();
    24.             }
    25.         }
    26.  
    27.         public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    28.         {
    29.             base.OnStateExit(animator, stateInfo, layerIndex);
    30.             foreach (var solverManager in _solvers)
    31.             {
    32.                 solverManager.enabled = true;
    33.             }
    34.         }
    35.  
    36.         public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex,
    37.             AnimatorControllerPlayable controller)
    38.         {
    39.             base.OnStateEnter(animator, stateInfo, layerIndex, controller);
    40.             _solvers = animator.GetComponentsInChildren<IK>().Where(c => c.enabled)         .ToList();
    41.  
    42.        
    43.             foreach (var solverManager in _solvers)
    44.             {
    45.                 solverManager.enabled = false;
    46.             }
    47.         }
     
    Last edited: Feb 8, 2023
  46. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    538
    For the previous issue, as a workaround I'm parenting the nodes that need to follow a node moved by IK, it's quite breaking my prefab hierarchy but better things working than not ! Though I'd like to have this working in the future so I can use unity parent constraint, so any answer is welcome. Unity constraint is great because it can use weights and several target transforms.

    Another issue I'm facing is that at runtime I'm making an instance of a character in game. Ofc the character is not in bind pose and thus when the solver reinitiate in the instance it seems it is using the current character pose and thus the clones are all having weird IK solving. I'm planning to pool the clones in the future. I tried to find an answer in the thread but couldn't find this specific usecase.

    What would be the best solution :
    - Copy the default state from the original IK solver to the instance ? If possible how ?
    - At start of the game prepare the clones at awake to fill the pool, it won't lazy initialize but well, that might be the price.
    - I'm also considering simply disabling IK as the clones are used for previewing actions.
    - Any other solution ?
     
    Last edited: Feb 10, 2023
  47. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Hey,
    Yes, they are different systems, but can be used together. Final IK to do all the IK stuff and PM to apply active ragdoll physics to it all.

    ik.solver.SetChain(spineBones, head, eyes, character.transform);

    Hey,
    You can't update IK from those animator callbacks because they get called before the animator applies the animation to the bones so everything you do from there will just get overwritten.

    If you have an animation clip with the default pose, could call animator.Play(defaultState, 0); and animator.Update(0.001f); before you init the IK.

    Best,
    Pärtel
     
    Whatever560 likes this.
  48. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    538
    Thanks for the animator tip, it should do indeed ! So basicall any chance to be able to update solvers before or at the start of unity internal PreLateUpdate phase ?
     
  49. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,560
    Yes, no chance I'm afraid.. I have tried to get something like OnAnimatorUpdated callback or something from the Unity devs, that would help me get rid of a lot of code trying to guess when the Animator is updated and also get rid of many potential bugs, but sadly the Animator has been abandoned for years now and nobody cares lol.
     
  50. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    538
    Thats a damn shame. How are we supposed to handle animation in our games then ... Anyways thanks for the plugin !
     
    Partel-Lang likes this.