Why won't target matching work with this ledge climb up animation?
Hello!
I am trying to create the climb up part for my ledge climbing system using the MatchTarget function on the animator. Here is the code within my ledgeClimbing.cs script inside the Update() function:
if(stateManager.IsClimbingUp)
{
GetComponent<Animator>().MatchTarget(aimPoint, transform.rotation, AvatarTarget.RightHand, new MatchTargetWeightMask(Vector3.one, 1.0f), 0.0f, 0.2f);
Debug.Log("Matching target");
}
aimPoint is the point on the ledge above that the player should reach.
And this is the code inside the animation manager in the LateUpdate() function. I used LateUpdate so I could be sure that the climbUp trigger had been set (tells animator to perform climb up anim) before I set the MatchTarget in the next frame:
if(Input.GetKeyDown(KeyCode.Space) && stateManager.CanClimbUp)
{
anim.SetTrigger("ClimbUp");
charControl.enabled = false;
stateManager.IsClimbingUp = true;
stateManager.IsClimbing = false;
StartCoroutine(WaitForAnim(2.933f));
}
The debug log indicates that the first if statement has been executed, so that is not the issue. I know this code will also execute it every frame, but I tried it just as soon as the space key is pressed but it didn't do anything.
The animation plays as if I hadn't called the MatchTarget function at all. Am I calling it in the wrong place?
The climb up animation has no root motion and is completely on the spot if that makes a difference.
Answer by Radiago · Jan 12, 2018 at 10:10 PM
Try waiting for the animator to say it's in the correct state, instead of a single frame. myAnimator.GetCurrentAnimatorStateInfo(0).IsName("climbup") returns a bool you can check.
Answer by canis · Feb 28, 2018 at 06:15 PM
match target only available on BaseLayer
when (animator.IsInTransition(0) == true) you CANNOT apply match target, warning will append in console
just like @Radiago said you need to wait until GetCurrentAnimatorStateInfo(0).IsName(XXX)
ensure the match target period are not overlap any other state, (2) happen and match target will cancel.
Your answer
Follow this Question
Related Questions
Animation/Movement Error 1 Answer
Click on Animation script throughout the game 0 Answers
Movement and Jump with animator 0 Answers
When I run this code Unity crashes(ANIMATOR RELATED) 0 Answers
Interchangeable animations in a script? 0 Answers