Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

IKPosition not working

Discussion in 'Animation' started by Griffo, Sep 6, 2014.

  1. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Hi,

    I've got a problem that I hope you can help me with, I'm using Aim IK to aim a weapon at the player (all works fine) then I'm using Mecanim IK to re target the left hand on the weapon when it's aimed at the player, the aim script ..

    Code (JavaScript):
    1. function LateUpdate(){
    2.     if((globalVarsScript.futureSoldierType1Alive[soldierNumber]) && (!knockedDown)){
    3.         if(seePlayer){
    4.             theLookAtPosition = player.position + transform.up * 0.2;
    5.             ikAim.solver.IKPosition = theLookAtPosition;
    6.             if(currentStateLayer02.nameHash == reloadState){
    7.                 lerpWieghtdown();
    8.             }else lerpWieghtUp();
    9.      
    10.             ikAim.solver.IKPositionWeight = lookWeight;
    11.         }else{
    12.    
    13.             lerpWieghtdown();
    14.             ikAim.solver.IKPositionWeight = lookWeight;
    15.         }
    16.    
    17.     }else{
    18.         ikAim.solver.IKPositionWeight = 0;
    19.     }
    20. }
    And the Mecanim IK code ..

    Code (JavaScript):
    1. function OnAnimatorIK() {
    2.     if(seePlayer) {
    3.            if(currentStateLayer02.nameHash == reloadState){
    4.                lerpWieghtdown();
    5.            }else lerpWieghtUp();
    6.     _animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,lookWeight);
    7.         _animator.SetIKRotationWeight(AvatarIKGoal.LeftHand,lookWeight);
    8.     if(leftHandTarget != null) {
    9.             _animator.SetIKPosition(AvatarIKGoal.LeftHand,leftHandTarget.position);
    10.             _animator.SetIKRotation(AvatarIKGoal.LeftHand,leftHandTarget.rotation);
    11.         }
    12.     }else{
    13.         _animator.SetIKPositionWeight(AvatarIKGoal.LeftHand,0);
    14.         _animator.SetIKRotationWeight(AvatarIKGoal.LeftHand,0);        
    15.     }
    16. }  
    When the Mecanim IK code is run the left hand moves to the effector but when the weapon points at the player the hand does not move down with the effector (as seen in the video) is this something to do with the call order?

    I'd appreciate any help you can give me, thank you.



    What I have just noticed is the bullet cases being ejected on the other side are being ejected above the weapon, so the transform positions of the bullet cases and the hand effector are not changing when the weapon is aimed at the player with the Aim IK .. But if you look the transform position of the hand effector looks to be moving with the weapon but not returning new position X,Y,Z .. Why would this happen ?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi Griffo,

    OnAnimatorIK() is called before LateUpdate(), so that why you see your avatar hand like this.

    To solve this issue you would need two IK pass. the first one to set your look at and the second pass to fix the hand on the gun.
    You can do this with mecanim, each layer can have a different IK pass, and OnAnimatorIK callback receive the layer index as argument to define which pass to solve.

    However I don't how Aim IK is implemented and if you could use it with mecanim in a OnAnimatorIK callback rather than LateUpdate().

    You can see an example of this in our bear apocalypse demo.
    https://www.assetstore.unity3d.com/en/#!/content/9896
     
  3. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Mecanim.Dev thank you for the reply, I'll look into it ..

    [EDIT] ..

    Tried the two pass but didn't work, I asked this question HERE and the developer of Final IK gave me an interesting answer.
     
    Last edited: Sep 8, 2014