Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Animator.MatchTarget broken with low fps

Discussion in 'Animation' started by adre, Jul 29, 2017.

  1. adre

    adre

    Joined:
    Mar 28, 2014
    Posts:
    37
    Hi everyone,
    i have a matchtarget controlled animation for climbing ledges.
    I just realized that it's not framerate indipendent, and when i have low FPS it does not work anymore.

    Any suggestion?
    Thank you in advance.

    These are the gifs of the behaviour, is easier to show than to explain:

    WITH GOOD FPS

    WITH BAD FPS


    I'm using a rigidbody character and this is the code i am using in FixedUpdate:

    Code (CSharp):
    1. if (anim)
    2.         {
    3.             AnimatorStateInfo state = anim.GetCurrentAnimatorStateInfo(0);
    4.  
    5.             if (Input.GetButtonDown("ps4_X") && climbHandPos != null  && !hasJumped ) {
    6.                 anim.SetBool("Climb",true);
    7.  
    8.  
    9.             }
    10.  
    11.             if (Input.GetButtonDown("ps4_analog_button") ) {
    12.                 GetComponent<IKControl>().lampActive = !GetComponent<IKControl>().lampActive;
    13.  
    14.  
    15.             }
    16.  
    17.             if ( state.IsName("Base Layer.Climb") && !anim.IsInTransition(0) && climbHandPos != null )
    18.             {
    19.  
    20.                 anim.SetBool("Climb",false);
    21.                 transform.rotation = climbHandPos.transform.rotation;
    22.                 GetComponent<IKControl>().ikLookActive = false;
    23.                 GetComponent<IKControl>().lookObj = null;
    24.                 GetComponent<IKControl>().ikRHandActive = false;
    25.                 GetComponent<IKControl>().ikLookActive = false;
    26.                 GetComponent<IKControl>().rightHandObj = null;
    27.                 GetComponent<IKControl>().leftHandObj = null;
    28.                 GetComponent<Collider>().enabled = false;
    29.  
    30.                 anim.MatchTarget(climbHandPos.position, climbHandPos.rotation, AvatarTarget.RightHand, new MatchTargetWeightMask(new Vector3(1, 1, 1), 0), anim.GetFloat("MatchStart"),anim.GetFloat("MatchEnd"));
    31.                 anim.MatchTarget(climbHandPos.position, climbHandPos.rotation, AvatarTarget.RightFoot, new MatchTargetWeightMask(new Vector3(1, 1, 1), 0), 0.4f, 0.7f);
    32.  
    33.                 hasJumped = true;
    34.             } else {
    35.  
    36.                 GetComponent<Collider>().enabled = true;
    37.                 climbHandPos = null;
    38.             }
    39.  
    40.             if (hasJumped && state.normalizedTime > 0.6f)
    41.             {
    42.                 GetComponent<Collider>().enabled = true;
    43.  
    44.                 hasJumped = false;
    45.             }
    46.         }
     
  2. adre

    adre

    Joined:
    Mar 28, 2014
    Posts:
    37
    Seems like flagging "Animate Physics" in the animator solved the problem.
    I'll do more testing and in case i'll update here.
     
    dyupa and theANMATOR2b like this.