Search Unity

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. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi! Yes you need Rigidbodies, Joints and Colliders to make your character a ragdoll. The RagdollUtility doesn't do that, use the good-old Unity's Ragdoll Wizard.

    I fixed the Array index out of range bug for the next version, it will check if there actually is a ragdoll, thanks! :)

    Regards,
    Pärtel
     
  2. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    I added the Ragdoll with the good-old wizard as you advised. But now I got new problem since in my Character Controller there is capsule collider that keeps the character on the ground. Because the colliders are overlapping the collider, rigidbodies and joints go all crazy everywhere.

    So I tried to set the Ragdoll colliders to IsTrigger. Now it's not going crazy anymore but when I turn the character into Ragdoll with the Ragdoll Utility it works (which is great!) but since the Colliders in the Ragdoll are set to IsKinematic the character just falls through the ground.
     
  3. arcdragon1

    arcdragon1

    Joined:
    Oct 15, 2012
    Posts:
    116
    Oops sorry! Everything went well Thanks!:)
     
    Partel-Lang likes this.
  4. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!

    You should have the character controller on one layer and the rest of the character (including ragdoll bones) on another. Then go to the Physics Settings and disable collisions between those two layers in the Layer Collision Matrix.
     
    theANMATOR2b likes this.
  5. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Ok, it's working now. Thanks.

    I will try to do something like this:



    http://perttuh.blogspot.fi/2013/10/unity-mecanim-and-ragdolls.html

    I quess I'll just add animation when the character rises, this example seems to choose from two animatios how it gets up. Something like this would be cool with Final IK Ragdoll Demo as well, just an idea. ;)
     
  6. bhads44

    bhads44

    Joined:
    Feb 19, 2013
    Posts:
    37
    Hi Partel,

    I need to dynamically set the number of bones used in Aim_IK script to suit different weapons. I know how to assign the bones and weights to the solver, but how do I set the number of bones first. What's the code to access this property in the script.

    Thanks.
     
  7. bhads44

    bhads44

    Joined:
    Feb 19, 2013
    Posts:
    37
    I just realised I could assign the bones and then set the unwanted bones to zero weight.
     
  8. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!

    Yes, you can just play a prone/supine getting up animation when the blending starts.
    You can use this code to check whether the ragdoll is prone(facing down) or supine (facing up):

    Code (CSharp):
    1. public Rigidbody bone; // Use the hip or spine
    2.  
    3.     Vector3 forwardAxis;
    4.  
    5.     void Start() {
    6.         // Presuming this script is on the root of the character and the character is standing up, facing it's blue axis.
    7.         forwardAxis = Quaternion.Inverse(bone.rotation) * transform.forward;
    8.     }
    9.  
    10.     // Returns true if the ragdoll is facing down
    11.     bool IsProne() {
    12.         float dot = Vector3.Dot(bone.rotation * forwardAxis, transform.up);
    13.         return dot < 0f;
    14.     }
    Hey, I didn't even think of that. :)
    You can also change the Bones by
    Code (CSharp):
    1. aimIK.solver.SetBones(Transform[] hierarchy, Transform root);
    but your idea is probably faster.

    Cheers,
    Pärtel
     
    theANMATOR2b likes this.
  9. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Hi Pärtel,

    how would you limit bone rotation inside a FBBIK (with Head-effector and Grounder)? In some situations my character has overstreched knees and I would like to limit the angle between thigh and shin to 85°. Tried "rotation limit hinge" script but I does not get it to work correctly...

    Also I would like to limit the angle for upper arm and lower arm with "rotation limit angle" if this is possible?!
     
    Last edited: Jul 3, 2015
  10. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!

    The Rotation Limits work with CCD, FABRIK and Aim IK solvers, FBBIK can not use them, it is a different kind of solver. You can use the Rotation Limits to constrain animation playing under the FBBIK, but not the FBBIK itself.
    If you told me more about the problem with overstretched knees with maybe a couple of screenshots, I might be able to give you some kind of a solution.

    Regards,
    Pärtel
     
  11. yos_316

    yos_316

    Joined:
    Dec 11, 2013
    Posts:
    6
    Hello.

    I want golf ball and club-head to be in the same position at impact in my golf game,
    What should I do?

    Thanks
     
  12. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi! If it requires just minor adjustments to the swing animation, you can do it like this:

    1. create an empty gameobject parent it to the root of the character, put it exactly where the club hits the (imaginary) ball in the animation, let's call it "hitPoint".

    2. write something like this (using FullBodyBipedIK):

    Code (CSharp):
    1. void LateUpdate() {
    2.             Vector3 ballOffset = ball.position - hitPoint.position;
    3.             ik.solver.rightHandEffector.positionOffset += ballOffset;
    4.             ik.solver.leftHandEffector.positionOffset += ballOffset;
    5.         }
    That is the easiest way to solve this in position space.
    You can extend it by adding a Mecanim curve for that animation clip that blends from 0 to 1 by the time of impact and back to 0. Then using that curve's value as the multiplier of ballOffset, so the offset effect blends in/out smoothly with the animation.

    Give it a try.. if its not enough and you need more range, I can help you figure out another solution that also rotates the club.

    Cheers,
    Pärtel
     
  13. yos_316

    yos_316

    Joined:
    Dec 11, 2013
    Posts:
    6
    Thank you very much for your prompt reply.
    I will try it! :)
     
  14. Deleted User

    Deleted User

    Guest

    Hi, im new to Final IK, its amazing, so easy to set up and its just working perfect.

    I got a quick question about your work.
    Im using now the Full Body Biped IK, with the Grounder FBBIK and the Look At IK.
    Works perfect.

    I got some Animations like a Wall Jump and more Acrobatics, sometimes the Hands ore Arms for example are out of control and just smashing in a Wall just because the Animation is playing this Direction, what´s the best way to tell the Character "Hey take care there is a Wall, get your Hand more to the Body to look more natural"?
    Is there a Grounder IK for hands?

    Thanks for the Answer ;)
     
    Last edited by a moderator: Jul 8, 2015
  15. Deleted User

    Deleted User

    Guest

    Hello, I am trying to pull a hand forward. I added AimIK component to the character, added a target in front of him and assigned it to the AimIK.Target, added all bones of a hand to the AimIK.Bones. Now while playing animation with mecanim, hand jitters, always returning back to the animated position. Could you please let me know what might be the cause?
     
  16. Lordinarius

    Lordinarius

    Joined:
    Sep 3, 2012
    Posts:
    94
    Hi, Does it support 2d physics raycasting for CCD ?
     
  17. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi, Useless Media,

    Grab this package. Its a FBBIK offset modifier (like Inertia, Amplifier, BodyTilt and others) that you can hook up with a FBBIK component. Take a look at the demo scene, move the box closer to the characters and see how the hands behave. Its not like th Grounder, it will just raycast towards the hands and move them closer to raycast origin if something blocks it.

    Hi, Denis,

    It's difficult to say.. What does the AimIK setup look like, can you give me a screenshot? Are you sure the "Aim Transform" is the weapon you want to aim, not the target? What do you mean by "trying to pull a hand forward"?

    Hi, Lordinarius,

    I'm not sure I understood the question, CCD has nothing to do with raycasting, it just makes the tip of the IK chain end up where you set the IK target to. If you find the IK target position by 2D raycasting, that is completely fine.

    Cheers,
    Pärtel
     
  18. Deleted User

    Deleted User

    Guest

    Hi Partel,

    I was just trying to aim hand in a forward direction. I setup it again from scratch, and this time everything works as expected, not sure how did I get the jittering last time. Thanks!
     
  19. anueves1

    anueves1

    Joined:
    Jan 10, 2014
    Posts:
    36
    Hi Partel,
    First of all i wanted to thank you for the awesome asset that Final IK has become and wanted to know if you could help me with this question:
    How would i go about networking the Aim IK, Grounder FBBIK and Interaction system components?
    Hope you can point me in the right direction.
    Thanks for Final IK and for your help.
     
  20. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi and thanks!

    For networking, it would be best if you just sync the IK target positions and interaction commands, every client should take care of their own solving. Otherwise you'd have a lot of bone transforms to sync.
     
  21. anueves1

    anueves1

    Joined:
    Jan 10, 2014
    Posts:
    36
    Thanks for the answer!
    But how would i go about networking Grounder FBBIK since its not using targets?
     
  22. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    You don't network it. Its just cosmetic stuff that each client should handle on its own.
     
  23. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    here I built an android demo of grounder + aiming pose done fully by effector targets. you can notice some issues of shaky legs (the legs has no effectors) and constrained(?) aiming (I'm rotating the soulders, w hand effectors under it)
    http://www.mediafire.com/download/1plmi52m5s2zz0h/grounderdemo.apk
    probably the best to use aiming animation (not walk) or upper-body layer. would it be possible to use grounder setup with upperbody fbik or how would that work?

    GifCapture-201507132303413901.gif
     
  24. MacluMan

    MacluMan

    Joined:
    Nov 25, 2013
    Posts:
    23
    Hello Partel
    I have the great need that the character does not have any type of collider attached. I did some tests but I did not succeed, you could help me with this or at least tell me I should consider to do so. My idea is that both raycast used to the position of the feet also determine whether the playing ground and if not then apply gravity.
     
  25. Hedonsoft

    Hedonsoft

    Joined:
    Jul 11, 2012
    Posts:
    168
    Hi Partel. I have my player setup to pickup a gun with interaction targets for the right and left hands. I put the HandPoser script on each hand. When I pickup the rifle with the right hand the left hand doesn't go to the target. I'm using a slightly modified version of the AnimatorControllerIK script. The aim and pick works but the hand placement is off.
     
  26. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!
    Why can't you have a collider for the character? You could put it on a layer that collides with only the ground and nothing else.

    Hi! When you darg a new character to the scene with nothing but the Animator and the weapon holding animation playing and the gun in his hand, is the left hand where it's supposed to be?
     
  27. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!
    Are you sure the legs are not shaking already in the animation? sometimes using Animator's "Foot IK" can do that.
    That gif is so small it's hard to see whats going on in there. I'll take a look at that apk later today, I have no android device with me atm.

    Cheers,
    Pärtel
     
  28. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi, I took a look at that apk.. Do you have colliders on the bones? Maybe the Grounder is raycasting against the colliders of the character. Make sure that layer is not included in the Grounder solver's layers. About the aiming, it is very difficult to say, I have no idea whats going on in that project, can you send something to me to support@root-motion.com?
     
  29. MacluMan

    MacluMan

    Joined:
    Nov 25, 2013
    Posts:
    23
    Hi
    Because my character all the time will be bouncing off the walls and climbing walls, not only the floor also around the stage.
    please tell me how to change this to not use any capsule. only use two raycast.
     
  30. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    It is not an IK-related problem really, but you could just raycast down and put the character to the hit point. Of course it will not collide with anything in the scene. I remember seeing a raycasting-based character controller in the Asset Store.
     
  31. Hedonsoft

    Hedonsoft

    Joined:
    Jul 11, 2012
    Posts:
    168
    The left hand isn't where it's supposed to be. I added FBBIK and put the hand where I wanted then duplicated the hand and attached it to the weapon but as you can see the hand's not finding the target
     
  32. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Maybe it's just not reaching that far? Set left arm Pull to 1 and all the other limb pulls to 0 and see if it reaches then. Or increase the Reach value of the left arm.
     
    Hedonsoft likes this.
  33. dibdab

    dibdab

    Joined:
    Jul 5, 2011
    Posts:
    976
    no, there are no colliders. it's the same setup as the grounder, the animations are the same too.
    switching off footIk helps a bit, adding effector target to the body helps a bit too, but the shaking's still noticeable.
    I've sent you the link to the package. (you'll need control freak for the inputs to work)
    thanks for taking a look.
     
  34. Hedonsoft

    Hedonsoft

    Joined:
    Jul 11, 2012
    Posts:
    168

    Fixed it Somewhere along the line I scaled the gun. Setting it back to 1 fixed everything. Stupid mistake but if my mistake helps one person I won't feel bad :)
     
  35. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi Partel,

    I'm here again with a little problem with the limbIK. I have already working the aim ik. Now i have the left hand placed when needed with the limbIK. All works fine. You pick up a gun, and the left hand is placed in the right position. If i start the aim state, the aim solver works great, but the left hand flickers up and down.... If i exit the aim state, the hand is placed again without any problem. I've tried to update the solvers in different orders, but the problem is still there. Any clue? It is all in LateUpdate, so i run out of ideas.

    Thanks!
     
  36. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!

    Is the Animator update mode on Normal or Animate Physics? Which solver are you updating first? Is any of the left arm bones included in the "Bones" of AimIK? Does the flickering occur at all times or only when you are moving the aim target around?

    Pärtel
     
  37. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    I'm sorry. You're right. I should give you more info....

    Her we go:
    I've tried updating first limbIk and Aim Ik. Both ways, same problem.
    I've tried with normal and animate physics, and it stops flickering, but the left hand is not reaching the grip position of the gun... And no shared bones between the two solvers...

    The aim target is still. no movemetn except the animation itself...

     
  38. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    I'm thinking the flickering comes from using Animate Physics that makes the Animator update only in fixed time step while you are updating IK each floating frame. So for the fixed frames you get one result and for the rest another, so it appears flickering.
    So set the update mode to Normal or update IK in LateUpdate only if a FixedUpdate has been called since the last LateUpdate.

    The left hand is not moving maybe because you set it's target position before you solve AimIK?
    If you need LimbIK to put the left hand back to where it was relative to the gun after AimIK solves, you need to:

    1. Store the position and rotation of the left hand relative to the right hand
    Code (CSharp):
    1. Vector3 p = rightHand.InverseTransformPoint(leftHand); Quaternion r = Quaternion.inverse(rightHand.rotation) * leftHand.rotation);
    2. Solve AimIK
    3. Set left hand IK target position
    Code (CSharp):
    1. limbIK.solver.IKPosition = rightHand.TransformPoint(p);
    4. Solve LimbIK
    5. Rotate the left hand bone to the weapon
    Code (CSharp):
    1. leftHand.rotation = rightHand.rotation * r;
     
    Danirey likes this.
  39. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Ok, that makes sense. I'll try out. Thanks a lot!

    So if i understand it right, to use animate physics, i need to call a coroutine from the LateUpdate to be able to use a waitForFixedUpdate and update the solvers after that?
     
    Last edited: Jul 20, 2015
  40. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Well, I've some results, but not perfect yet.
    The code is this:
    Code (CSharp):
    1. void LateUpdate ()
    2.         {
    3.  
    4.         aimik.solver.Update ();//first we sove the aim ik
    5.        
    6.         //now, we set the target for the limb IK(left hand)
    7.         if (useIK) {//useIk is only to place the left hand / the aim parameters are handled outside
    8.             if(actualGun){
    9.                 limbik.solver.SetIKPosition(actualGun.GetComponent<GUN>().weaponComps.gripPosition.position);//if we have a gun in the hand
    10.                 limbik.solver.maintainRotationWeight=1f;
    11.                 limbik.solver.bendModifierWeight=1f;
    12.                 limbik.solver.IKRotationWeight=0f;
    13.                 limbik.solver.IKPositionWeight = Mathf.MoveTowards(limbik.solver.IKPositionWeight, 1F, Time.deltaTime);
    14.             }
    15.         } else {
    16.             limbik.solver.IKPositionWeight = Mathf.MoveTowards(limbik.solver.IKPositionWeight, 0F, Time.deltaTime);
    17.         }
    18.         //and solve it
    19.         limbik.solver.Update ();
    20.                
    21.         }
    Still using animate physics in the Animator component. Now, aim works fine, so nothing changes with that. Limb ik doesn't flicker, so that problem is solved i think. The position of the left hand, has a bit difference of position between aimIk weight 1 and 0. If not aiming, which is when i check the grip transform position and rotation, i set the position and rotation so the left hand is well fitthing the grip of the gun. With the same position of the grip, which is the ikposition of the limb solver, when enter the aim mode, with the aimIk weight set to 1, the left hand is slightly up compared with the grip position that hasn't changed. Here are some pics showing the problem. But the left hand is positioned fine on aim , and gets a slightly lower position when exit aim:(Sorry if this is a bit confusing, but i have some problems translating my thoughts..:p)

    Idle(no aim weight nor limb weight):

    Limb ik weight 1, and aim 0:(Note in this one the hand is below the grip point.)


    Limb ik and aim ik weights set to 1:

    In this last picture you can see the components values. And now the hand is fitting the gun correctly.

    Said all that, what i'm still doing wrong?

    Thanks a lot!
     
  41. Menatombo

    Menatombo

    Joined:
    Feb 6, 2014
    Posts:
    26
    Hoping Partel still reads the thread. I'm considering getting this, but a question. (Please don't shoot me I didn't read every post on this thread.) I would like to know if you can use FBX or mecanim animations and trigger final IK through a FSM? Really curious, because if so you'll have to take my money! :D I just don't want to get something that doesn't work with the currently set up Mecanim characters.
     
  42. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    This is exactly what i'm doing, so i think YES is the answer! FBX with Mecanim driven animations and through FSM or BT, make use of the IK different solvers. You have two pics in the previous post showing that!

    Cheers!
     
  43. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    I don't own this atm, but I was just wondering how easy is it to set up holding different weapons/items ?

    Would it just be something like you pose the character, save that pose somehow, and then attach it to an item via a script or something. Then when the player equips the item, it would load the pose from the script ?

    What would the term for this be? The class index in the website documentation is huge so I don't even know what I would look for there.

    *edit I think I found it. Is it basically the "Linking Effectors to Objects" video ?
     
    Last edited: Jul 23, 2015
  44. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi again, sorry for the long wait..

    What if you don't update AimIK at all, is the left hand still below the grip? What if you debug the position that you get from
    Code (CSharp):
    1. actualGun.GetComponent<GUN>().weaponComps.gripPosition.position
    ? You can use
    Code (CSharp):
    1. Debug.DrawLine(Vector3.zero, actualGun.GetComponent<GUN>().weaponComps.gripPosition.position);
    to see if the target is where it's supposed to be at that time.

    Hi!

    Yes you can trigger Final IK API calls through anything. You can assign a gameobject as an effector target or you can set the target positions/rotations and weights directly through code. If you need to do some more complex stuff like combining IK solvers and updating them in a specific order, running them on top of each other, your FSM needs to be able to call functions in a specific order in LateUpdate.

    Hi! Yes, you are correct, it can be done like in that video. Although I usually advise users to have a weapon holding pose animated as normal. It is so much easier then to use IK to adjust it for different weapon types, do procedural recoil and procedural aiming while still being able to animate reloading and weapon switching.

    Cheers,
    Pärtel
     
  45. Hedonsoft

    Hedonsoft

    Joined:
    Jul 11, 2012
    Posts:
    168
    For lerping AIMIK weight in//out so my character raises/lowers the gun smoothly I'm doing the following

    Code (CSharp):
    1.  
    2. if (Input.GetKeyDown(KeyCode.F))
    3.         {
    4.             aim = !aim;
    5.             if (aim == true)
    6.             {
    7.                 anim.SetLayerWeight(1, 1);
    8.                 aimik.solver.SetIKPositionWeight(Mathf.Lerp(0,1, Time.deltaTime*.1f));
    9.             }
    but this isn't working, the arms still snap into aiming position rather than moving there smoothly. What am I not doing?
     
  46. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi!
    It is probably not IK that is snapping, but Mecanim. You are setting layer 1's (probably the upper-body aiming layer) weight to 1 in a snap, not blending it smoothly.
    AimIK weight will never reach 1 with that code. Each time you press F to enable aim, it will lerp from 0 to 1 by Time.deltaTime *0.1f which means it will only reach 1 if your frame rate happens to be 0.1 frames/second at that time.

    Try this instead:
    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.F)) aim = !aim;
    2.  
    3.         float aimWeightTarget = aim? 1f: 0f;
    4.  
    5.         // Continuous lerping, no matter if the F key is down or not
    6.         aimik.solver.IKPositionWeight = Mathf.MoveTowards(aimik.solver.IKPositionWeight, aimWeightTarget, Time.deltaTime);
    7.  
    8.         // Make the first layer's weight the same as AimIK weight. This is the easiest way. You might want to use another variable that lerps to aimWeightTarget faster that AimIK weight.
    9.         anim.SetLayerWeight(1, aimik.solver.IKPositionWeight);
    10.  
    11.         //... or you might want to use an AnimationCurve instead:
    12.         //anim.SetLayerWeight(1, aimLayerToAimIKWeight.Evaluate(aimik.solver.IKPositionWeight));
     
    Hedonsoft likes this.
  47. Hedonsoft

    Hedonsoft

    Joined:
    Jul 11, 2012
    Posts:
    168
    Looks much better! The code is a lot cleaner too. Thanks as always Partel :)
     
  48. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi all!

    If you import Final IK to Unity 5.2.0 beta, you'll get 2 compiler errors from the CharacterBase.cs demo script about PhysicMaterial friction.
    Just delete the lines that produce the errors, I will do this for the next release.

    Pärtel
     
  49. rstorm000

    rstorm000

    Joined:
    Aug 19, 2010
    Posts:
    229
    Hi! I just bought this. What's the ability to use this to make based animations that can be used later? Looks great!
     
  50. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    2,552
    Hi, thanks for the purchase and welcome! :)

    You can assign some gameobjects as IK effector targets, then animate those gameobjects in runtime with the Animation Window. Then you also need some kind of an animation baker to bake that stuff to keyframes.

    I was developing a proper solution for this a while back, but hit a brick wall, so it was put on hold until Unity opens up some Humanoid animation creation API and some other things.