In this lecture, we're going to make our screen even busier.
We're going to add our animator controller in our animated window here and give our play out a little
idle animation.
And to quickly tidy up all the nonsense I've got splashed around in my level here, I'm going to drag
a big old space, click on the eraser tool and then just clear out all of my playing around I was doing
with my rule tiles.
Also, I was being really fast and loose.
And if you note here, my active tile map is the water tile map.
So I was drawing all those platforms on the water tile map.
We should be drawing this on the platform's tile map.
What I'm going to do is click on that and click on my rule tile and then just paint directly over the
top of what I've got here already.
Bit pop up, but I'm putting now I've replaced all of those tiles with my rule tiles so that if I go
and add some new stuff in here, then it knows what's going on.
So I've just updated it there with all tile information.
Now what I'm going to do is create our player idle animation.
We need to first of all start with window and then find animation and find the animator window.
I'll just grab that and pop that down the bottom I think next to my project and console.
And I'm going to be throwing a couple of terminologies here.
If you're not familiar with animation in unity, then it could seem like I'm saying the same thing over
and over.
But let's have a look at the terminology.
First of all, we have the animator component.
This is a component that we put on our game object.
We'll pop this on our player and this is what assigns animations to the game object, which will be
our player through an animator controller.
What's the animated controller?
Well, this is the arrangement of animations or and transitions.
This is the state machine that says go from running to jumping to idle to shot to whatever it might
be.
That's the animator controller that controls the animations.
And the animations are the specific pieces of motion says show this frame, then that frame and that
frame, or move this to this, to that.
And we also need to have a Sprite renderer so we can display the 2D Sprite on the screen, actually
visualize it.
Now, the steps will go through to set up our characters idle and all this lays out as a challenge.
In case you've done this before, we talk about animations in a couple of our unity courses.
Side note, make sure you check out all of the game dev TV unity courses so that you can get the full
experience and you can educate yourself to the absolute max.
But here's the challenge.
If you've already done animations in the past, import the sprite sheet and slice.
We've done that already a couple of lectures ago, so we've got a head start already.
Add the Sprite renderer to the player.
We'll do that in a moment.
Create idle animation clip.
So in other words, find the player sprite sheet and find the specific sprites that look like there.
The animation is kind of standing on the spot, popping up and down and then create a character animated
controller, add the idle animation to the animator controller.
So we've got that in there and then add the animation to the player so that the player can stand there
and bounce on the spot.
Finally, assign the character animator controller to the player.
So there are the steps.
Feel free to come back to this in the future.
If you want to take this on as a challenge, do so.
Now, if you look at this and you say, what's going on here, then no worries, we will do this together,
which we'll jump into now as a first step.
Let's make ourselves a player.
Right click in the hierarchy.
Create empty.
I will call this.
Shall I call it something silly?
Yeah, we'll call him Ginger.
And in brackets the player.
Just in case you're more old school and you like to call the player the player.
Rick, what are you doing?
Calling him, giving him a crazy name.
Ginger, I'm going to reset the transform.
That's great to make sure we haven't gone and put it way off in some sort of weird Z position.
It's going to be 000.
And next we'll add a component.
The first component we need here is the animator.
And note here that it's looking for a controller.
What is the animator controller?
In other words, what's the thing that's going to tell me what to do to tell the component, what to
do?
So that is something we set up in our project.
It's going to be an actual asset we have in here.
So I will go into my assets directory, right click, create a new folder which I'll call animations
where we will pop all things animation related.
Open that up, right click in here create, let's find animator controller and we'll rename this to
B player.
If I double click on that, open that up, you'll see that we've got a couple of things in here already.
You can zoom around, you can use the middle mouse button as we've done in other things.
Move this.
This is a state.
It's the state of exit, which basically means get out of this animation or get out of this entire animated
controller.
The entry point, this is where we're entering into.
And just another thing, any state.
So that could be if you want to have some rules that say whether you're jumping or running or swimming
or snorkeling, whatever it might be, you can do a particular thing from a particular state.
So we'll get into this again in a moment.
Just wanted to give you a quick look, see at it for now.
What we need to do is create an animation.
So back on to project, we'll find ourselves our player sprite sheet.
So for me, it's the SBA player, Ginger.
Why is it called Ginger?
Well, I gave him red hair and I thought Ginger maybe his name should be Red.
Actually, that'd be a smarter name.
But anyway, we live with our choices in life, don't we?
So that's fine.
I'm going to pull up the little preview window thing.
We can sometimes forget about that, but there it is.
There our preview.
Let's see if we can find things that look like Idol.
That looks like a roll, that looks like a Klein.
That looks like a bit of a bounce.
That's a run.
I think it's going to be somewhere around here.
So five, six, seven, eight.
So you can see there's a number of individual sprites, individual images that have been drawn.
And when you play them together, obviously I'm just scrolling backwards and forwards here on my keyboard
to show you these, but it looks like a little a bouncy bounce on the spot.
So it's going to be from five through to eight in this particular tile set.
And I'm going to highlight all those I'm holding down shift and using my keyboard.
Or you can do shift and your mouse and I'm going to while these are selected I will right click create
and look for animation.
Boink.
There we go.
It's called new animation.
We'll call this idle because that's what he's doing is idling.
And this is living at the moment, this dot anim file which is basically saying go through frame five,
then six, then seven and eight, five and six and seven and eight.
Grab that and we're going to put that into our animations folder.
Back to our animations folder, you can see that we've got our idol and we've got our player, animator,
controller, idle animation.
And you know, what I want to do is drag this into my animator, so I'll just grab the animator and
dock it over to the right here so we can see our files and we can see the animator at the same time.
So you can see what I'm doing, which is grabbing the idle animation, dragging that idle animation,
which consists of our four frames of idle, and just dropping it into our animated controller that is
now added as the state of idle.
And you can see this little line here is saying a transition basically as soon as anything says, hey,
use the animator controller, which will happen when Ginger, our player starts is instantiated in the
world and say, right, do the animation straight from the entry point, go immediately into idle.
Now if we click on Idle, we can see a couple of things here.
You can change the speed.
If you think he's bobbing up and down too quick, you can make it slower or faster by changing the speed
here.
Actually, what I will show you for completeness is let's go to window, find animation and then find
animation.
So with the animation window, if you haven't done much animation, then you might be wondering how
do we what is the animation?
What does that all mean?
Well, if we click on idle animation, then our animation window will show what's going on here.
You see, there's four frames in here.
One, two, three, four.
And if we open up the information on Sprite, you can see that the Sprite that we've put in here, it'll
show us that first one.
So the Sprite five, Sprite six, Sprite seven is Sprite eight and it's added those in here.
And when we push play, it's going to blink, blink, blink and then loop back to the start blank,
blank, blank, loop back to the start.
So that's how our animation is going.
So when we created our animation by highlighting those four sprites and said, turn it into an animation,
this is what it just did.
It said on the first frame, put the first thing on the second frame, put the second thing and so on.
So back to the animator window.
We've got our idol in there.
Next up, what we need to do is to tell our player.
So click on player to tell it, to use the animated controller that we've just set up the rules for
the animation, if you will.
So click on the little selector.
There's only one in our scene player double click on that.
That will assign the player animated controller.
Now to be able to see our character on the screen, we need to do what?
We need to add a Sprite renderer.
So click on add component search for Sprite and then add in the Sprite renderer.
Now we need something to see on our screen.
So at the moment where we have Sprite as none, we need to put a particular Sprite in there that we
can see.
Let's click on that and select just any of our sprites here.
This is not going to be what the player sees.
This is just a representation.
So I'll choose what I think is the first idle animation.
Seems okay now.
That should be somewhere in our world.
But where is it?
If we click on Player, it's missing a little bit of a micro challenge for you here.
See if we can figure out what's going on and fix that.
Well, if you guess that it's hiding somewhere underneath all of these layers, you got it right.
And because we've set up our sorting layers, let's go and add a sorting layer for the player.
So I'm going to jump all the way up to the default layer where it says layer, default, add, layer.
We will add in a new sorting layer which will be clicking on plus we'll call this player hit enter.
Now back to clicking on the player and scrolling down to where we see salt layer.
And I'll change this from default to player.
Actually, you know what I need to do is make sure it's in the right spot.
So back to add layer in here, go to sorting layers and let's see, the player needs to be probably
on top of everything.
To be honest, there might be a little bit of being underneath the platforms.
Yeah, I think if the player is the very last layer here, then it should be over the top of everything.
So let's have a look at that.
Click on the player, drag the player on over.
Yeah.
Now the player is going to bounce around over the platforms.
Okay.
So the moment of truth, if we click on play, find our game window in here is our camera set up.
It should be looking at the character.
Nothing happens.
Well, if we look down at our animator, you can see this blue line is just stopped.
So basically I think what's happened is it's gone through all four of those sprites bump very quickly
and then it stopped.
So now what we need to do is find out idle animation.
Click on that look over in the inspector you can see loop time, click on loop time that will just say
loop our animation or loop our frames over and over and over.
Now when we click on play, he should be doing a little bounce.
There he is doing his idle excellent.
So there we go.
We've set ourselves up the starting point of our player, just a little idle animation.
And because we've created our animated controller, we can now add other states in here such as running
and jumping and climbing ladder.
So a good start on animations.
I'll see you in the next lecture.