I’m learning how to control objects with Mecanims, and I have a question about the usage of the animator.
Maybe how I’m solving the problem is the wrong way, and if there are different solution I’m obviously interested.
I have a animation of a movement on a card object. Card object is contained in a Container object. I need that when I hit a button the card does the animation and, at the animation’s end, the Container moves to the final position of the animation.
Now: The animation is activated by bringing the animator to a “Movement” state. After the movement state, the animator makes a natural transition (it just has an Exit time) to another state: Movement_Complete. This other state does not have any animations on it, because is a transition state.
I have a script on the card that each Update() checks if the animators goes in the Movement_Complete state (I use
var = cardAnimator.GetCurrentAnimatorStateInfo(0) and then
if(var.IsName("Movement")). If it does: it calls a function that sets the position of the Container to the position I want.
Here is the problem: when the Container arrives in this position, the card model transform node is already in the correct position. I think this happens because the transform node is not translated from the animator, BUT the card is still in the position of the last frame of the last animation (the movement one). So the final effect is that the movement animation goes well but as soon I set the final position of the Container, the card gets teleported further.
I tried lots of possible solutions that came to my mind. I think that the fact that there is not another animation in the Completed_movement state, means that the card keeps using the last animated keys until some other keys overwrite the animation. So I create a StandStill animation of 2 frames and I put it in the Complete_Movement state, that works but not well. The problem of this solution is that the card returns to it’s correct position, THEN the Update() function checks if the animator has entered in the Complete_Movement state and so it puts the Container in the correct position. So for a (very bad and visibile) frame the card returns to the origin of the animation.
Someone knows how to fix it? Or knows a better solution?
Thanks a lot