Unity Development Part 4
- kw4u19
- May 23, 2021
- 3 min read
This development session took place during week 7
My aims for this session:
Fix the issue where the player can no longer jump
Work out how to make the background follow the player
Learn how to use the animator
The jump issue
When I changed the player object sprite from a simple square with a collider of the same shape, to the shaman sprite that was created by Daniella, the collider was clearly no longer the correct size or shape for the player. When I resized the collider so that it fit on the player properly, so that the boundary ended at the players feet, I found that the player could not jump anymore. I am pretty sure this is a problem with script and not really being able to tell when the player is touching the ground.
Here is the first player movement script I wrote, compared to the one I wrote today:
I added in the bool IsGrounded = true, and two new methods, while getting rid of the the old public bool method.
And as you can see, the parts of the script that checks whether the player is grounded (touching the ground, objects tagged as ground in the scene) have been re-written.
It now checks if the player has a collision with any object tagged "Ground" and if they do, they are able to jump. This fixed the issue. I can't explain why the first method did not work but I am glad that I found another one that did.
The background
This was an incredibly simple fix, and i'm a little embarrassed that I wasn't able to work it out before but I have just made the sky background a child of the camera which already has a script attached to it that makes it follow the player. So therefore, the background does now move when the player does.
The Animator
As of now, I have a walk animation and a run animation for the player. I do not yet have an idle animation but have realised that it is an essential addition and will be asking Molly (my animation department) to make one.

Above is a screenshot of the animator and the three animations that I have applied to the player. The idle animation at the moment is just a dodgy two frame bobble that is acting as a template, its frames taken from the other animations.
I understand that the Idle animation had to be made the default state and then I use parameters to make it so the animations transition upon key presses. But I am not yet sure how to set up these parameters and how to write into the script their methods.
Researching how to use the animator controller:
I read through this page (at https://www.studica.com/blog/unity-tutorial-animator-controllers) which details how to set up an animation and create it, set up the animator, and then use the parameters to make bools or triggers to be used in the script. It also shows how to write the script to get the right animations to play at the right instance. This was really helpful for me to get a better understanding of what I needed to do.
A bool would be used when checking if multiple things are true or false and then chooses the right action, where as a trigger works one way. So if I want the player to be able to transition between the three animations (idle, walk and jump), I will need to use bools rather than triggers. Later on when I implement the ability animations, I will be able to use triggers instead as they can only be used when in the default idle state.
This session had been quite productive, I managed to fix two of my issues while learning more about unity and making those earlier mistakes were positive in that sense. Furthermore I now have a good understanding of how to use the animator and will blog that process of applying those animations in the next session.
Comments