I'm lost. How to coordinate two sprite animations each other?
Hi! I don't find anything similar on the internet, and I really have no idea how to do it. I'm trying to do a character similar to MetalSlug. 2D lateral game. The legs have their own animation, in that way you can walk forward and look ahead or look diagonally up.(while the legs are still walking)
The animation of the legs and the animation of the upper part of the body have already the same number of frames, but when I look diagonally up, the body is uncoordinated with the legs, because it start the animation from the beggining.
The question is.... How can I start the animation from the same frame as the frame of the legs?
I do not know if I explained well. But watching the movement of the MetalSlug player I think it is understood. (I suppose that I have to save in a variable the position of time in which the "Animator" of the legs is, and then apply it to the animation of the body. But I do not know how to do it.)
Answer by Jirakun · Jan 19, 2019 at 02:53 AM
Hey! Ok, SOLVED! I answer (in case someone arrives with the same problem).
//Two animator, one for legs, one for body
Animator animLegs; //animator for the legs;
Animator anim; //animator for the full body;
//Create a function. I called him "CoordinateSprites()"
void CoordinateSprites()
{
//Get the frame from thee animLegs
float aniTime = Legsanim.GetCurrentAnimatorStateInfo(0).normalizedTime;
// this is to GET the normalizedTime. And normalizedTime is the % of the animation. 0 is the beggining of animation, 0.5 the middle, 1, is finished.
//Set normalizedTime from "animLegs" to "anim"
anim.Play("", 0, aniTime);
}
And this is it! Now you only need call the function at the beggining of the animation.
You can create a bool in Update(), if bool is true , call CoordinateSprites(), if not, nothing.
Press "rec" in the animator and check your bool in the first frame.