Unity Development Part 5
- kw4u19
- May 24, 2021
- 3 min read
This development session took place in week 8.
In this session, I will be working on the implementing the player animations (idle, walk and jump) using the animator controller and script writing. As established in the last blog post, I need to set up the animator and create a set of bool parameters that will work in unison to make transitions between the separate animations possible.

I did begin this session by first cleaning up the sprite sheets because I noticed there were still some issues on them. The animations also changed in scale when moving from walk to jump so I moved them into photoshop cleaned up the mistakes and then resized the frames one by one. I could have got Molly to do this herself but I had the time and didn't mind.
And here are the before and after for resized frames on the jump animation:
The marking were very subtle but against the background in unity, they stuck out like a sore thumb and unfortunately I couldn't find a way to scrub them out within unity or resize the frames in there either.
In the animator, I set up the three animations with transition states between each type so it formed a cycle of sorts. There are too booleans I needed to use and I have named them isRunning and in the image below it says "isGrounded" but I later realised I had already used this phrase in my player movement script so it has been changed to "isJumping".

So as an example, from player Idle to the run, the parameter would be a boolean titled "isRunning" and that would be selected as true and coming back from running to idle, that parameter is set to false.. On these transitions, I also needed to uncheck the exit times and instead check fixed duration. Furthermore the loop time needs to be checked on every animation, as we don't want the animations to stop playing while in use.
The transition state from idle to jump, in comparison, is named "isJumping" and is set to true. For the transitions between jump and running, I got very confused but eventually work out I needed both parameters on the transition from jump to run, being "isRunning, true and isJumping, true".
Now I needed to make changes in the script, so there is a real instance where isRunning and isJumping are either true or false and have their differing outcomes.

In the start method I have made sure the controller get the player animator and then in the update set up when the animations should be playing with their parameters stated as true or false.
IsRunning is only true when the player is moving along the horizontal axis, shown in the first if and else statements. Secondly, isJumping is only ever true when the player pressed jump, so after the jump method, I have set the bool for "isJumping" to true.

For jumping, I just needed to put its bool in the same method that checks if the player is touching the ground. When they are, jumping is not happening, so false.
This development session was so successful. I am really happy with how quickly I picked up using the animator because at first it was very intimidating and I also really struggled with working out which booleans needed to be used where but I got it!
The next steps to think about are that I need to add into the script the code to make the player sprite flip when the player moves left or right along the horizontal axis. And as assets are being produced by the team quite quickly now, it'll be good to start getting them all into unity and working on the structure.
Comments