In this lecture, we're implementing some letters so that we can climb up the ladder and climb down
the ladder.
And I'm going to give this to you as a big old challenge.
So let's get started.
Just a reminder, you've got a piece of the ladder that you downloaded, hopefully when you downloaded
all of this Sprite set.
So you've got the ladder piece in there.
What we're going to do straightaway is take on a mega challenge.
So that being a challenge is going to be to implement ladder climbing.
We've done all the different elements of this, so this will be a good opportunity to bring it all together.
Remember, you need to set up your climbing tile map.
Well, I'm going to call it climbing.
You can call it whatever you want.
You could call it ladder if you wanted.
But just in case we have things other than ladders, say ropes in the future, I'm going to call it
climbing and also the climbing layer.
So we can check to see if we are currently touching something that should allow us to climb to create
the climb ladder method check to see that we're touching the ladder and to apply climb velocity to the
Y axis if we are pushing up or down.
And then in the next lecture we'll be setting the animation.
And there's also an issue where the character slowly slides down the ladder.
So don't worry about those just yet.
We'll do that in the next lecture, but get the base functionality of climbing the ladder set up.
Take on that challenge.
See you back here when you're done.
First step in here.
Let's set up some of our functionality.
I will go over to my tile map grid, right click to the object.
We will find tile map and I'll create another rectangular tile map.
I'll call this the climbing tile map.
Well, here, I'm going to go over to my layers.
We do have ground.
I will add a layer in addition to ground.
Will call this climbing great.
And then back over into the climbing tile map.
And we will change this to be climbing right there.
We should also do our sort order at the same time, shouldn't we?
So I didn't mention that in the list of things to do, but it just popped into my brain just then that
we'll need to have.
Plus, layer five will call climbing, I imagine the climbing layer we'd want to have on top of the
platforms underneath the player.
So the player should definitely be on top of the ladders.
The ladders could be on top of the platforms, I think.
But that's up to you and that should be okay.
Now, within our tile palette, I'm going to grab my ladder and just pop it up in the top there.
It'll ask me where I wish to save that.
We have our assets sprites and you know, I put the rule tile in there because we needed close access
to it, but we don't need that for our ladder.
So I'm going to pop my ladder into the tiles.
We'll call this ladder.
That's fine.
Saved that up.
And now in our palette, we have a letter.
I'm going to click on that and pop one into the scene.
We can't see it.
That means we've done something incorrect in here.
First of all, am I on the right tile map?
Yes, I am.
Am I clicked on the thing?
Yes, I am.
Let's have a look.
What else is going on here?
Click on the climbing tile map.
It could be that we haven't actually said what the sorting layer is.
So under additional settings sorting layer, we need to say that I am climbing bump.
Hey presto.
There we go.
Okay.
I also didn't tell you to do this, but hopefully you've figured it out that you need to play around
a little bit with the collision on the ladder.
So let's have a look at what we've got on our platforms.
We have the tile map, render a tile map and there is a composite collider, 2D that looks like what
we need.
So back over into our climbing, we'll add a composite collider to DX and of course we need to add a
tile map collider to DX to that.
And you can see we have a collider on there now that doesn't look like a very good collider doesn't.
So let's go and edit that if I jump onto my sprite itself, so click on the Sprite and you can see we
have the Sprite editor in here.
We can jump up to Sprite editor and change the custom physics shape.
And within custom physics shape, I'm going to click in the top left drag all the way down to the bottom
right bump.
Okay.
And now we've got a custom shape.
I'll just bring these in a little bit, because sometimes you don't want the player kind of hanging
right on the edge of the ladder.
You want to make sure they've got themselves a little bit in the middle of the ladder.
Now, if I click Apply X out of that, click on my climbing tile map and it may not look right for you.
It might still look the old way.
I had to click and click back on the tile map collider for a to take on that physics shape that we put
on it.
I still don't like.
We've got the little green lines in there.
I'll have a look at that.
If we get stuck on those, then we'll play around with a few things here.
It looks a little bit buggy to me, but we may have done something wrong.
We'll come back to that if need be.
What we need to do next is jump over into our scripts, jump on, play a movement I'm going to find.
I actually create a climb ladder in update, climb ladder, parentheses, semicolon.
I like to have the things in the order they appear run then flips right then climb ladder.
We've got run and then flip sprite and then down the bottom here we'll do our climb ladder.
So void climb ladder parentheses.
Kelly Braces Let's do the movement stuff first.
So we need to give ourselves something very similar to run.
So what do we do and run?
Well, we had a vector two that was all about the lefty righty, and that's the x axis.
And then we applied that to velocity.
So I'm going to copy all of this.
Copy, copy.
Pop this down into climb ladder.
Pasty, pasty.
It's good, I think to once you've understood the concept, it's okay to reuse your code as long as
you know what you're doing.
You don't want to just copy and paste and have a big old guess at things that's not so good.
Instead of player velocity, let's rename this climb velocity.
Actually, I'm going to highlight climb velocity, highlight copy and then change that in the other
spot.
There we go.
So basically we need to flip these around instead of saying keep your existing Y velocity, we're going
to say keep your existing X velocity.
So you know what I'll do?
This is going to look a little bit messy, but I'm going to do it the messy way just so you can see
what's going on here.
Copy that.
Pop it up to this line above new vector to it's one of these things and in here I will delete the first
bit of that delete and I'm just basically using the line below.
I'm doing it this way.
So you can see really clearly what I'm doing on my screen.
My rigid body velocity x is the first part of our equation.
Comma, what do we need next?
Well, we need this move input times by some sort of climb speed, so we will move.
Import export.
This is why this time multiply by we don't have it yet, but we will multiply it by a climb speed.
Okay.
And then I'll delete that just so we've got rid of it.
Quan speed.
We need to create double click copy all the way back up to the top.
We'll find our serialize field serialize field and this will be of type float.
We'll call it climb speed and we'll initialize it at five just because that seems to be a nice number
to initialize all these things at all the way back down again to climb ladder.
We've got our velocity being climb velocity.
Great.
And then the other thing we need to do in here is make sure you're only able to climb if you're touching
the ladder.
So let us create our if statement.
You know, once again, we'll go find what we did in what was it?
It was on jump.
That was if your capsule collider is touching a particular thing so we'll highlight that copy it pop
down to climb ladder if my so if not my capsule collider is touching layers layers mask get mask what
is the mask we're interested in here?
It's going to be climbing with an uppercase C.
How do I know it's climbing back over into unity.
Click on our climbing tile map.
You can see that we've got a sorting layer climbing scroll to the top.
You can see we've got our layer climbing.
If I to click on that, go to the add layer, I could double click on here, copy that to get the exact
naming.
So I know I haven't messed that up.
And then back over into our climb ladder method and we're using climbing as the particular layer we're
interested in.
So this is all just exactly the same as the previous lecture where we're talking about the touching
a particular layer for touching the ground so that we could jump.
If you're not touching that, then return.
Don't do anything further.
If you are touching that, then we're going to do this particular thing.
Let's save that up and see how we're going with our functionality thus far.
Double check that we've got our climbing tile map set up correctly.
It is climbing and it's called layer climbing.
Click on the player.
It's going to be some era somewhere in here, I'm sure.
Run, run, run.
Well, nice.
And we knock over our ladder.
That is, my friends.
Not at all what I was expecting.
The reason that's happened, if we click on the climbing tool map, the rigid body on our ladder, that
was kind of funny.
I totally wasn't expecting that.
We don't want it to be dynamic.
Do we want it to be static so we can't bump into it and knock it over?
I can run out to it, but you know, bump, I'm bumping into it at the moment and that's not what we
want.
I can climb a little bit sort of when I've bumped into it, but we need to resolve this bumpiness.
So if you've got this behavior as well, or if you've just been following with me, just have a think,
pause a video and see what we need to do to stop us bumping into this.
And you know what?
Any time you bump into something that you want to run through, it's usually because we need to make
it a trigger.
A trigger is a type of collision where it doesn't stop the rigid bodies moving.
It doesn't allow us to have that bump into effect.
So we'll make our tunnel map collider and is trigger for our climbing tunnel map.
And when I run over, I can move up and I can move down as well.
Excellent.
So that's exactly what I want.
Can I jump off the ladder?
No, I can't at the moment because we have set up our jumping so that you can only jump when you're
touching the ground layer.
So that's something for us to consider.
Do you want you play to jump off a letter or do you want to say no, no, if you're on a ladder, you
have to float off the ladder.
But for now we've got the functionality that I wanted, which is we can run up.
We can run down only when we're touching a ladder and we've got the drift issue that I was talking about
was slowly floating to the ground.
And also our animation continues to be the idle animation.
So those are things we will work on in the next lecture.
Good stuff and I'll see you in that next lecture.