Search Unity

How to smooth IK SetIKPositionWeight??

Discussion in 'Animation' started by Denis-Valjean, May 10, 2015.

  1. Denis-Valjean

    Denis-Valjean

    Joined:
    Mar 25, 2015
    Posts:
    39
    Using this tutorial: http://docs.unity3d.com/Manual/InverseKinematics.html.

    But the movement of grabing is too fast. Tried lerp with no sucess. Found this other thread:

    "
    i found the solution to this, it's a bit tricky. you must have an animation raising the hand and add a curve to it then insteat of ikweight = mathf etc. put

    1. float reach = anim.GetFloat("AimWeight");
    2. //and then
    3. anim.SetIKPositionWeight(AvatarIKGoal.RightHand,reach);
    this page helped me http://docs.unity3d.com/Documentation/ScriptReference/Animator.SetIKPositionWeight.html"

    But I dont know how to config those curves. Can Anyone post please an example of smoothing ik grab? Thanks.
     
  2. nyudeb

    nyudeb

    Joined:
    Mar 20, 2015
    Posts:
    19
    Hey, I just looked the same page http://docs.unity3d.com/Documentation/ScriptReference/Animator.SetIKPositionWeight.html.
    I found a solution about it :
    - Put a new value in your animator like "float HandWeight"
    - In your OnAnimatorIK, do something like this :

    if (gameObject.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).IsName("talking"))
    {
    animator.SetFloat("HandWeight", 1, 0.1f, Time.deltaTime * 0.3f);
    animator.SetIKPositionWeight(AvatarIKGoal.LeftHand, animator.GetFloat("HandWeight"));
    animator.SetIKPosition(AvatarIKGoal.LeftHand, leftHandObj.position);
    animator.SetIKRotation(AvatarIKGoal.LeftHand, leftHandObj.rotation);
    }
    else
    animator.SetFloat("HandWeight", 0);

    It will smoothly increase the HandWeight by Time.deltaTime * 0.3f. You can play with the 0.3f for the speed.

    Enjoy. :)
     
  3. opticglass

    opticglass

    Joined:
    Dec 30, 2020
    Posts:
    5
    This is like travelling back to the past to find some answers for the future. Thank you for this!
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    It's also known as necroing a post. Please just use the like button in the future as that is what it's for.

    Also note, this post is in the physics forum but it's asking about Animation which has its own forum.

    Thanks.
     
  5. opticglass

    opticglass

    Joined:
    Dec 30, 2020
    Posts:
    5
    Why put the reply button here? Your reply button quoted the answer and added it to my response. So if you guys at Unity think this as a necroing post, just remove the reply button instead. I am only trying to appreciate the answer provided here by someone else's question because it has also resolved my issue.
     
    anelkhvan likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    It's great to acknowledge but you can appreciate by using the like button rather than necroing a 7 year old post so others then see it as an update when there's no extra information. We get a lot of this and it adds more noise to an already noisy forum.

    Removing a reply button isn't a practical solution nor is it a feature of the forums. We trust that devs will self moderate and read the forum code of conduct which specifically mentions necroing: https://forum.unity.com/threads/unity-community-code-of-conduct.743180/
     
  7. opticglass

    opticglass

    Joined:
    Dec 30, 2020
    Posts:
    5
    Well the reason for commenting on this 2015 post is for others to see (if they will encounter the same issue) that the solution from 7 years ago is still working with the new versions of Unity. If the docs were clear enough, some questions wouldn't need to be asked and you wont see me lurking here in the forums.
     
    anelkhvan likes this.
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,491
    If you have an issue with Animation and its docs then please create your own thread on the Animation forum rather than necroing a post here from 7 years ago which will achieve nothing. Posting on the correct forum specifying what you want would be more productive.

    Your justification here isn't valid and as I pointed out above, is against the Community code of conduct.

    I'll move this post to the Animation forum where it belongs.

    Thanks.
     
  9. opticglass

    opticglass

    Joined:
    Dec 30, 2020
    Posts:
    5
    What I am trying to spread is awareness that this still works because the docs were not so clear to guide us "devs".
    So if you think this is necroing and your policy tells you so, so be it.