Chapter 5.4 : The Animator
Well I got the character moving but it's currently stays in one sprite. How do I solve this? Lucky for me Unity has an animation feature that allows me to bring in my sprite sheets into the feature and arrange them in the precise order and timing to make it animate smoothly. This also needs a bit of animation to allow it to work.
As mentioned before, the Animator component allows me to assign animation to a GameObject in my scene. The Animator component requires a reference to an Animator Controller which defines which animation clips to use, and controls when and how to blend and transition between them as shown below :
Once this is done I go to the Animator tab on the top beside the Scene tab. Here is where I would add Bool,Float or other elements to know when to access the sprite.
Now there's two methods in doing this, either we create a block and add transitions between them as well as adjusting the timing and parameters of the animations. It'll be something like this:
However the method Im using is more easier. What I did was right click on the canvas and I would select Create State > From New Blend Tree.
Blend tree are used for allowing multiple animations to be blended smoothly by incorporating parts of them all to varying degrees. Here is one that I have done :
The amount that each of the motions contributes to the final effect is controlled using a blending parameter. I can also add in more animation clips by just pressing the + symbol on the right and under motion I locate the clip that I want to put in.
As for the scripting part, its easy.
1) put GetComponent<Animator>(); in Void Start
2) you can either set the parameter to bool or make it float. Here's how I did mine (Check the last few lines in the script)
Only the Player's sprites and Enemies sprites would I use Blend tree as it allows the movement to be smoother. The rest such as the flowers or treasure chest I would only use Animations clips or transitions just to add a bool to allow it to function properly.
And that's all there is for Animator for me :)
Comments
Post a Comment