Animation state
In this blog page I will showcase my approach to making the sprite of Megaman move!
Firstly, I start off with collecting the images from Aula and download them into my own P.C. After that I open up Unity and make a 2D Template project.
Following the boot up of Unity, I import my assets into a sprite folder I made. I would shift and left click from left to right to select all of them and then make the "Sprite Mode" to multiple. I also changed "Filter Mode" from "Bilinear" to "Point(No Filter)". I changed "Compression" to "Normal Quality" as well, this will help so Megaman does not look blury because he is pixelated the Unity will try to smooth it out.
I started to use "Sprite Editor" and to select one image and then slice it up by grid count into individual sprites. You can clearly see how they are cut. In the beggining I had a little trouble with doing this because i kept my Collums and Rows 1 by 1. But then I shortly realised that the Collums had to be 4 and Rows to be kept at 1. I will repeat this process for every sprite.
Dragging through the first sprite from the Idle animation onto my hierarchy so I am able to see it. Then using ctrl + 6 (Animation) I made it into a moving animation with 5 seconds intervals. Following this, I started working on Megaman_Wake. I sliced it as normal but with 15 Collums rather than 4 and I made sure that they are all central.
After this I animated the wake state of megaman I changed the sample state to 10 which would make it a lot slower than 60. This would make it look a lot more natural. I'm using the base character of the idle animation but I put over the wake animation on top of that sprite.
After opening "Animator" I drag it onto my own windows tab so it is easier to use, then I click on my sprite to be able to see the nodes. Then I switch over to the "Animation" tab and create a new clip.
I want to add the Idle animation (only one frame) to our nodes. So I start off by adding it and setting the sample to 1. Switching over to "Animator" i connect the 2 nodes "Wakeup" and "Idle" by right-clicking "Wakeup" and making a transition over to "Idle".
This is the results so far!
Following these results, I then start to add another clip called "blink" and used the "Idle" animation with a sample of 10. Then I connected "Idle" and "Blink".
I have clicked on the connection between "Idle" and "Blink" which then I changed exit time to 4 (so it plays 4 times) and transition duration to 0. Then I have made another link from "Blink" to "Idle" and changed exit time to 1 and transition duration to 0. So this way the character would look like he is just blinking in his "Idle" animation.
I've created a new clip called "Jump" and added my sliced sprites inside. I have changed the sample to 20 so it looks a lot more natural. Then i want my character to jump when the player clicks a button so I've linked it from "Idle" and "Blink" to "Jump". I've also set it not to have an exit time or transition duration, as I want it to be quite fast since clicked. But to make it jump once a key was pressed I need to add some parameters. I also need to add some coding to wrap everything together so that when I click spacebar my character actually jumps.
This code basically makes my character jump when clicked spacebar. When spacebar is clicked it would go from "Idle" or "Blink" straight to "Jump". The code line used for this is: "if(Input.GetAxis("Jump") != 0f)" and " anim.SetTrigger("jump");". Then I added the code to the player form the hierarchy to make him jump. Which he does but he remains stuck in "Jump" as there is no connection from "Jump" to anything else. So I made a transition between "Jump" and "Idle" so after it does "Jump" it goes back to it's "Idle" default state. I also added the state "Run" in my animator with the animated run. I add a bool (which is like an on/off switch) after I connected my nodes.
I added some more coding to our coding from before to make sure that when we click right click the running animation would come into play. I've finalised the code to make sure that my character doesn't get stuck in the "Run". The last 2 coding lines "anim.SetBool("IsRunning", true);" means that if he is running it will transition to "Run" and the counter-part of this is, "anim.SetBool("IsRunning", false);" when the running stops (after one whole animation) it would switch to "Idle" or "Jump" I also had to make sure that all the connections had the right conditions set to them.
One example is this, which is from "Jump" to "Run".
Final Result!
(the whole process is here including the wake I just couldn't make a gif of it properly due to my software that I am using!)