Search Unity

  1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    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. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    597
    Thanks for the feedback here and on my mail, best support like always!
     
  2. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    Not really, but you could use a bend goal to fix the bending direction.
     
  3. fup

    fup

    Joined:
    Jan 18, 2016
    Posts:
    39
    I've been trying to mitigate a problem resulting from a calibration process. I have the player stand in an I shape to get the shoulder width and the T shape to get the arm lengths. I then adjust the upper arm and forearm transforms to match the player's arm length. After calibration the arms are the perfect length when standing in the T-shape but if the player stretches an arm out fwds then it cannot reach the vrik controller target, and so appears shorter than it should be. If I adjust so the player can reach forwards then the arms are way too long if held out to the sides, down to the side, or above the head. Have you encountered this problem? And if so how did you fix it? (I've tried adjusting the arm length to always reach the vrik target at runtime but, although it works nicely to some degree, it becomes unstable when the arm is pulled back since there's some weird shaking between - I think - VRIK attempting to bend the arm and my code shortening it, which I cannot fix. This is why I was asking if the elbow could be locked temporarily since i could lock it, while shortening, and then let it bend again when in the "reach zone").

    I hope all this makes sense. I could do with some help. I've spent ages on it. Any advice is much appreciated! :)

    upload_2017-7-29_21-19-54.png
     
  4. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    You can dynamically adjust the length of the arm by multiplying the localPositions of the forearm and hand bones in LateUpdate. VRIK will adapt to that without any twitching. Here's an example script for you.

    There is also this commented out line around 273 in IKSolverVRArm.cs, under "// Additional pass to reach with the shoulders", try changing it to:
    Code (CSharp):
    1. VirtualBone.SolveTrigonometric(bones, 0, 1, 3, position, Vector3.Cross(upperArm.solverPosition - shoulder.solverPosition, hand.solverPosition - shoulder.solverPosition), positionWeight * 0.5f);
    use that, might give you more reach with the shoulder bone.

    Best,
    Pärtel
     
  5. fup

    fup

    Joined:
    Jan 18, 2016
    Posts:
    39
    Awesome Partel! Many thanks.

    re your shoulder adjustment. If I uncomment that line I get this error:

    Error CS0117 'IKSolverTrigonometric' does not contain a definition for 'SolveVirtual'
     
    Last edited: Jul 30, 2017
  6. fup

    fup

    Joined:
    Jan 18, 2016
    Posts:
    39
    Damn. I've tried your solution but I still have the same issues. The problem is occurring because of when the scaling factor is calculated. To calculate it I calculate the ArmReach at startup and then each update calculate the distance from the upper arm world position to the VRIK target position. If this is further than the ArmReach then we scale.

    If the upperarm to target distance is calculated at the same time it is applied in your script then it is incorrect since the world position of the upper arm is still in the default pose and not actually where it is. This is me sitting at my desk wearing the rig. The red circle is where the upper arm position is at this moment in the code execution.

    upload_2017-7-30_13-6-26.png


    Notice how the upper arm position is incorrect and therefore the arm is stretched.

    If I calculate the scaling factor *after* the IK is applied (so the upper arm world pos is correct) and apply that *before* the IK in the next update the instability returns.

    Any idea how to rectify this?
     
  7. simonej33

    simonej33

    Joined:
    Jan 11, 2017
    Posts:
    4
    Hey Partel,

    Love this asset and how useful and easy to use it is, thanks!!

    We are however having some issues with the LookAtIK where the spine not only rotates around the vertical axis, but also leans far too much backwards or forwards so that if the character is looking at the head of someone and they come too close the character will almost look as though they are playing 'limbo'.

    The only work around we've found so far is to just reduce the weight of the spine, however that removes the twisting around the vertical axis which is something we really enjoy.

    Is there any possible work around to this?

    Thanks,
    Simone
     
  8. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    Replace that line with
    Code (CSharp):
    1. VirtualBone.SolveTrigonometric(bones, 0, 1, 3, position, Vector3.Cross(upperArm.solverPosition - shoulder.solverPosition, hand.solverPosition - shoulder.solverPosition), positionWeight * 0.5f);
    as I said in my last post.

    Hey,
    Dont calculate the distance from the upper arm to the target. Before the IK update, the upper arm will be either where it is animated or at it's default position relative to the root if no animation used. So it's distance to the hand target is basically meaningless. You could get use the distance from the head target to the hand target instead or use the distance from the hand bone to the hand target after IK has solved and use it to stretch the arm for the next frame.

    Your joints seem to be dislocated because the character's skinning is "robotic", fixed to the bones. You'll probably need to use scaling instead of localPosition.

    Hey,
    So if the target character is really close, the target will be quite high for the spine and that will cause it to bend backwards. I added a public Vector3 spineTargetOffset to IKSolverLookAt.cs, it's in world space, pease
    Code (CSharp):
    1. https://www.dropbox.com/s/7dalvr8uokh10oj/IKSolverLookAt%20Spine%20Target%20Offset.unitypackage?dl=0
    .

    Just write
    Code (CSharp):
    1. lookAtIK.solver.spineTargetOffset = Vector3.down * 0.3f;
    to make the chest look at the approximated position of the target character's chest.

    Cheers,
    Pärtel
     
    simonej33 likes this.
  9. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    36
    It took me a while to track it down, but it turns out that I had the animator's update mode set to AnimatePhysics. When I switched back to the default setting, everything worked perfectly.

    Thank, Pärtel.

    PS Welcome back from holidays. I hope you had a good time -- you're a hard-working guy, and deserve a break every now and then!
     
    Partel-Lang likes this.
  10. staron82

    staron82

    Joined:
    May 22, 2017
    Posts:
    6
    Thank you for a quick response.

    I tried using positionOffset, but the left hand doesn't move an inch. I'm sure it's because I've done something dumb, but I'm not sure what.
    Code (CSharp):
    1. Vector3 currentWeaponOffset = leftHand.bone.TransformPoint(leftHand.bone.position) - currentWeapon.TransformPoint(currentWeapon.position);
    2. leftHand.positionOffset += rightHand.rotation * currentWeaponOffset;
    3.  
    4. ik.solver.Update();
    currentWeapon is an empty GameObject placed where the hand should be.
     
  11. leftblank

    leftblank

    Joined:
    Feb 21, 2014
    Posts:
    1
    I'm currently building a VR / AR hybrid in Unity, where I'm controlling an IK rig using VRIK, then sending the VR controllers positions to an iOS device using network transforms to mirror the IK rig's movement in ARKit. I'm having trouble implementing pinch to scale the scene locally on the iOS device.

    I'm attempting to uniformly scale down a parent GameObject containing the IK rig which has its Head target connected to SteamVR Vive headset and its Hand targets set hand controllers positions. The vectors that describe the absolute positions of the controllers are being sent over the network to the iOS rig, so I'm applying the same scale factor to those, so that the targets match up to the scaled down character. However, the IK rig appears to break when scaling the character down, and in particular the legs appear to be too far apart, and the hand movements no longer look correct

    Could the problem be to do with the internal relative transforms within the IK rig needing to be modified? And is there a better approach?
     
  12. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    36
    Except that now my wrists twist badly (and look pinched), even though I have a TwistRelaxer on the forearms.

    With the mode set to AnimatePhysics, the TwistAnimator works and the wrists look fine -- but the collider doesn't work.

    With the mode set to Normal, the colliders work fine but the wrists are twisted (and adjusting the settings on the TwistRelaxer just moves the twist problem from the wrist to the elbow).

    I'm using Grounder, in case that makes a difference somehow.
     
  13. simonej33

    simonej33

    Joined:
    Jan 11, 2017
    Posts:
    4
    Thank you so much! This is super useful and can both fix this individual problem and be changed for any other similar issue

    Would also like to say that the VRIK with leapmotion is super cool and fun to play with!!

    Really appreciate the fast response and help and the great asset!

    Thanks,
    Simone
     
    Partel-Lang likes this.
  14. Ctttdaddy

    Ctttdaddy

    Joined:
    Mar 17, 2015
    Posts:
    14
    Hello,

    I have a major issue that has been holding up my development for a while now.


    I use VRIK with VRTK to run most of my characters interactions and movement. I have run into something I would say is a glitch. I originally thought the glitch was something in VRTK but after attempting to recreate the problem in VRTK I now believe it is in VRIK. The issue is that when I have the player pick up a gun and shoot, the bullet instantiation place does not match what I have set.


    I Have my VRIK model set up and working fine.


    Within TKRV, you have Controllers that have a “Controller Attach Point”(Rigidbody). These attach points set the position and rotation of objects that are picked up or held.

    Within VRTK you also have “Snap Handles”(Transform). These position the Object that you are interacting with when being held.


    I have made my Controller Attach Points children of the players hands and positioned them on the palm. If you do not do this, if the controller goes past the IK of the players hands, your gun goes through.

    This methods looks perfect and works very well with one exception.


    When I shoot the gun by Instantiating a bullet and adding force forward, the bullet is created, somewhere other than the transform I specified.

    I have done tests with VRTK to verify if it was VRTK or FinalIK causing the issue by matching the transform position and rotation with a box and following the same process of adding the CAPs and SHs and testing the gun. It works as expected using just VRTK. Something is strange with FinalIK from what I can tell.

    Has anyone else experienced this issue?

    To test, I have added a DrawRay debug line and everything looks perfect but when I shoot the gun, it is very far away from the transform of the reference… Please help.
     
  15. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    rightHand.bone.TransformPoint instead of leftHand.

    Hi,
    Some of the values in Locomotion settings need to be scaled down as well, as it does not account for the scale of the character. Namely footDistance, stepThreshold, maxVelocity, velocityFactor, stepHeight, heelHeight and offset, also minHeadHeight in the Spine settings. I didn't notice any problem with the arms though, even when scaling the Pilot down to 0.1 in the basic demo.

    Hey,
    Please import this updated version of TwistRelaxer, should work the same with all update modes. You'll need to assign the "IK" slot in the TwistRelaxer components.

    Hey,
    It's just the update order of things, you are probably shooting the bullet before VRIK has solved for that frame.
    Add your bullet shooting script to a higher value in the Script Execution Order than VRIK and use LateUpdate to shoot the bullet.

    Best,
    Pärtel
     
  16. fup

    fup

    Joined:
    Jan 18, 2016
    Posts:
    39
    Hi Partel,

    What's the best way of using FinalIK/Puppetmaster to add slight variation to an animation? For example, varying a hit reaction or locomotion?

    (I've tried going through your samples btw and a few the ones I've looked at don't work as expected or have stuff missing. The ShoulderRotator scene says "move the hand effectors to ... ", but there are no effectors I can find and the targets are null in the IK component.The HitReaction scene says rotate the camera using the RMB, but that doesn't work. etc)
     
  17. Ctttdaddy

    Ctttdaddy

    Joined:
    Mar 17, 2015
    Posts:
    14
    [QUOTE="
    Hey,
    It's just the update order of things, you are probably shooting the bullet before VRIK has solved for that frame.
    Add your bullet shooting script to a higher value in the Script Execution Order than VRIK and use LateUpdate to shoot the bullet.

    Best,
    Pärtel
    [/QUOTE]

    Thank you for your reply but this does not resolve the issue. I have added the script to LateUpdate and moved it up to be executed first on my gun. I have also moved VRIK and FBBIK to the bottom of the characters script order.
    Im at a loss for why this is happening...

    I will say that my bullet fire script is being called by an animation event.
     
  18. kerrmedia

    kerrmedia

    Joined:
    Nov 4, 2015
    Posts:
    209
    I was watching this quick video of Final IK used with a animated spider, which is exactly what I need to do. I bought Final IK, but was wondering if I could quickly just find what I need to get Final IK working with my spider?

    AnyIK Spider Foot IK

     
  19. BernieRoehl

    BernieRoehl

    Joined:
    Jun 24, 2010
    Posts:
    36
    Thanks, Pärtel -- that new version worked perfectly!
     
  20. Jaha

    Jaha

    Joined:
    Jan 23, 2014
    Posts:
    2
    Hello! I am trying to figure out how to setup multiple "right hand" targets and triggers for the same interactable object. I can't seem to figure out how to define which "right hand" target a specific trigger is referencing when interacting with the same object. For instance, the inside and outside handle on a door. Suggestions? Thanks.

    Right now I have a single interaction object script attached to the door, a have a trigger zone and raycast target setup on each door handle. I also have a right hand target on each door handle. The targets seem to work fine but when interacting with the door the right hand ALWAYS reaches for the same handle. Is there a way to assign a target position per trigger?
     
  21. staron82

    staron82

    Joined:
    May 22, 2017
    Posts:
    6
    Hmm, the hand still doesn't move.

    Full code:
    Code (CSharp):
    1. Vector3 toLeftHand = leftHand.bone.position - rightHand.bone.position;
    2.         Vector3 toLeftHandRelative = rightHand.bone.InverseTransformDirection(toLeftHand);
    3.  
    4.         leftHandRotationRelative = Quaternion.Inverse(rightHand.bone.rotation) * leftHand.bone.rotation;
    5.  
    6.         aim.solver.Update();
    7.  
    8.         leftHand.position = rightHand.bone.position + rightHand.bone.TransformDirection(toLeftHandRelative);
    9.         leftHand.positionWeight = 1f;
    10.  
    11.         rightHand.position = rightHand.bone.position;
    12.         rightHand.positionWeight = 1f;
    13.  
    14.         ik.solver.GetLimbMapping(FullBodyBipedChain.RightArm).maintainRotationWeight = 1f;
    15.  
    16.         Vector3 currentWeaponOffset = rightHand.bone.TransformPoint(rightHand.bone.position) - currentWeapon.TransformPoint(currentWeapon.position);
    17.         leftHand.positionOffset += rightHand.rotation * currentWeaponOffset;
    18.  
    19.         ik.solver.Update();
     
  22. Ctttdaddy

    Ctttdaddy

    Joined:
    Mar 17, 2015
    Posts:
    14
    After much testing it looks like the HandPoser script is causing the issue. When it is active, the bullet seems to come out of a point aligned with the forearm independent of the rotation of the hand. and not the gun-bullet position. I would appreciate any help. Thanks!



    In the image it shows a Red raycast from the point and direction that the bullet should come out of. The Green raycast is the point and direction the bullet actually does come out of.
    These are both using the same code to script.
    I have no idea what would cause this in the HandPoser script...
     

    Attached Files:

  23. Ctttdaddy

    Ctttdaddy

    Joined:
    Mar 17, 2015
    Posts:
    14
    figured it out. It was "fix Transform" unchecking that cleared my problem up, in case anyone else has the problem
     
  24. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    Have you seen the "Amplifier" demo yet? It is exactly about adding some variation to animation.

    Hey,
    If it's been called by an animation event, it will happen somewhere in Mecanim's update process regardless of where the script is in the Execution Order. Use a flag, set it true in the animation event and then in LateUpdate check for that flag and fire the bullet if true.

    Hey,
    Go to the "Grounder" demo, you'll find a robot bug in there, that spider can be set up exactly like that bug.

    Hey,
    You could use the tags. Assign different tags to the targets, then you can change interactionSystem.targetTag to choose which target to use.

    Oh, I see... effector.position if positionWeight is greater than 0 will override positionOffset, so that's why the hand is not moving. You'll have to add that position offset to leftHand.position.

    Hey,
    That actually makes your bullet shoot from where the gun was in the end of the last frame. Use the solution I mentioned above.

    Cheers,
    Pärtel[/QUOTE]
     
    kerrmedia likes this.
  25. wherget_dfki

    wherget_dfki

    Joined:
    Oct 4, 2016
    Posts:
    4
    Quick Question/Feature request: Why does InteractionObject use its own Message implementation and not UnityEvent<Transform>? I found UnityEvents pretty neat to work with (maybe not less prone to breakage though).
     
  26. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Right, just added that to the next version.
    If you'd like to have that right away, just add this code to the InteractionEvent class in InteractionObject.cs:

    Code (CSharp):
    1. [TooltipAttribute("The UnityEvent to invoke on this event.")]
    2.             /// <summary>
    3.             /// The UnityEvent to invoke on this event.
    4.             /// </summary>
    5.             public UnityEvent unityEvent;
    Then, below, to public void Activate(Transform t) add
    Code (CSharp):
    1. unityEvent.Invoke();
    And finally,
    Code (CSharp):
    1. using UnityEngine.Events;
    to the top of the file.

    Cheers,
    Pärtel
     
  27. kerrmedia

    kerrmedia

    Joined:
    Nov 4, 2015
    Posts:
    209
    Checking out Grounder Demo, thank you!
     
  28. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    158
    Hey! Great asset! With this aim ik.. how can I get it to follow the center of the cam with mouse look?
     
  29. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey, thanks!
    Just set AimIK target to camera.trasform.position + camera.transform.forward * 10 or some distance like that.

    Best,
    Pärtel
     
    mattis89 likes this.
  30. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    158
    Thanks! Appreciate the quick reply =)
     
  31. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    158
    I dont really understand how to do it .... I parented a gameobject to the camera a bit away from the player and assign it as target.... that worked.. thats how ?
     
  32. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Yeah, that basically the same thing, just without using code. Should have just told you to do that, I'm just used to doing everything via code, sorry.

    Best,
    Pärtel
     
  33. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    158
    I think its better to use code but I just didnt understand how to use that line of code.. thanks :)
     
  34. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    26
    Does it possible to allow VRIK to extend the arm of the character rather than stopping it when the controller/IK target are further than arm length? My goal is to allow players to reach object even if they have arms a little bit longer than normal (I already scale the character relative to height, but it not enough in some cases). If you know the game Lone echo, this is how the IK body is done and I wonder if we can do it with VRIK?
     
  35. kerrmedia

    kerrmedia

    Joined:
    Nov 4, 2015
    Posts:
    209
    my grounder demo is cool, but its a human character interacting with an obstacle course.
     
  36. tayloreichhorst

    tayloreichhorst

    Joined:
    Nov 14, 2013
    Posts:
    3
    Hey Partel,

    Quick question for you. I have a moving platform that my play space moves in sync with. The problem I'm having is that when using VRIK, the feet fall behind and it looks like the player is being dragged. I want to make it appear that the play space is moving, but the player is free to relatively move around the play space without the playspace's velocity effecting the feet. I hope that makes sense. How would you suggest making this work?
     
  37. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    There's no automatic arm stretching included yet, but technically you can stretch them by just multiplying the localPositions of the forearm and hand bones, with a script like this.

    There's also a spider-like bot in there, click on the "Bot" button once the demo starts. Find the bot under "Characters" in the scene hierarchy, you can set up your spider just the same.

    Hey,
    Check out the "VRIK (Moving Platform") demo to see how to solve that issue.

    Cheers,
    Pärtel
     
  38. cinetech

    cinetech

    Joined:
    Oct 25, 2016
    Posts:
    2
    Hey man,

    Have the exact same problem! Don't suppose you have any tips on how you implemented the Syncvars and commands??
     
  39. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    258
    Hi there, you could check that on the main player object that you have the networking components added and the final IK stuff, do a islocalplayer check. If you have your own IK script you should sync those variables (via SYNCVARs and COMMANDs). Hope that helps, if not I can revisit. Is there any error you see, or what is the behaviour for your setup?
     
  40. cinetech

    cinetech

    Joined:
    Oct 25, 2016
    Posts:
    2
    Thanks Khos!

    I think I am close!! Will have to play around some more today but your idea concept is a good start. I think my problem is that the client is using local transform targets where I need to send the actual client running the players transforms to each client.

    Ill keep at it. Hopefully won't need to bother you digging up an old project!!

    Thanks!!!
     
  41. caden-burleson

    caden-burleson

    Joined:
    Aug 1, 2011
    Posts:
    19
    Hey everyone! I recently got Final-IK a few weeks ago and can't figure out how to get my character to move with Final-IK attached... Here's a gif of what's happening currently : http://gph.is/2w98sVj
    Can anyone help me out on how to get the hips to move with the character?
     
  42. Partel-Lang

    Partel-Lang

    Joined:
    Jan 2, 2013
    Posts:
    1,419
    Hey,
    Just parent those IK targets to the collider gameobject.

    Best,
    Pärtel
     
  43. ColtonK_VitruviusVR

    ColtonK_VitruviusVR

    Joined:
    Nov 27, 2015
    Posts:
    80
    Hey @Partel-Lang,

    Just checking if there is a better solution, other than this, to the animate physics problem yet?

    Cheers,
    Colton
     
  44. Vitali-Kirpu

    Vitali-Kirpu

    Joined:
    Dec 5, 2012
    Posts:
    10