In this lecture, I'm going to show you my amazing pixel art skills, because I've provided you with
a mushroom that we're going to add some physics material to DX two so that we can bounce to get out
of sticky situations.
We're also going to fix the issue where the player was sticking to the walls.
We're going to make it so you can't stick to the walls anymore and you slide up and down them smoothly.
Let's start first by adding our bouncy mushroom.
So I've gone and created a crazy little mushroom for you.
I'm going to put it in my sprites folder.
You can download it against this lecture.
Side note I created this in libraries right after following along with our pixel art course.
So if you have any interest whatsoever in making a way better mushroom than the mushroom I made, you
can go through the pixel art course and get some pretty cool pixel art skills really fast allows you
to make little things like what I've made, and I'm going to bring that in my mushroom.
Here it is.
In here you can see a little mushroom.
If I click, I get the preview over yonder.
Okay, just a little red mushroom, nothing too fancy.
But I wanted to have something we could bounce on.
I also need a spot in my level here where we can bounce.
I'm going to put this over here, I think.
Just rearrange my level very briefly, jump onto the eraser, make sure I'm on the correct tile map
platforms, tile map.
Just do a little bit of deletion in here so we've got something to bounce on and then go boing from
A to B.
I think that'd be pretty nifty.
Get rid of a couple of these things as well, because when I was prototyping this, I kept bouncing
up into the roof, which is kind of fun, but be good to have none of that roof bouncing going on.
And I'm also going to click my player hit and move my player over to the left, more of the start of
the level type thing down in this little spot just there.
We'll be putting my mushroom here.
So what we need to do is create a new tile map, which is going to be all about bouncing on things.
So click on tile map grid, right click find to the object and then tile map and then rectangular.
I'll name this bouncing tile map and we'll go and add the fundamental things we need.
So we need our tile map.
Collider To DX Add component.
We need our composite collider to DX to have a rigid body.
Yes, we have a rigid body in there already.
So we need the tile map.
Collider We need the rigid body and we need composite.
Collider 2D and one of these things in here, we need to mark as static.
So rigid body, 2D static so that our tile map doesn't go flying down into the nether regions.
Nether Is that the right word?
Netherworld Nether regions I don't think that's quite correct actually.
I think netherworld might be more accurate.
Sorry if I've said the wrong thing there.
Now next up, we need a process, our mushroom.
So I'm going to click on the mushroom, drag it over into the tile map.
That should ask me to save something somewhere.
It has.
We're going to put this in.
Let's see.
Assets and then tiles.
And that will be the mushroom.
Excellent.
And you can see it's kind of tiny on there.
That's because we haven't changed the pixels per unit.
So I'm going to click on the mushroom, look over on the right hand side, pixels per unit should be
32 because I created it as a 32 by 32.
We're going to apply what we're here will jump into the Sprite editor.
Just play around with the collision of this.
I'm going to actually create a custom physics shape that will looks like it does nothing, but you have
to click to start the process.
So I'll click in the bottom corner here or drag.
I think I need to do yet drag and then I'm going to drag the points just to where I need them.
If you need another point, I won't put this exactly lined up.
I'll put a bit over to the left side, a little bit forgiving.
If the player kind of lands around about there, it'd be fine.
It'll do some bouncing click anywhere on the line that will create a new point.
Pop that all the way over to there another point.
Clicking points, clicking points.
There we go.
Now we've got our customer's physical shape.
Click on Apply X out of that.
This shape should now have some good physics on it.
If I'm selected on the bouncing tile map, super important click on the mushroom and then go into the
world and click to drop that in there.
You can see that it doesn't appear, although you can see the little outline of the collision doesn't
appear because of sorting order.
So let's find our tile map renderer sorting order.
Let's see, this will be the same sorting as the platforms, I think.
I don't see that the mushroom would ever be in front or behind of the platform.
It is its own entity.
So we'll say it's at the same visual level as platforms.
Now we can see it.
We also need to handle collision.
So let's go up into layer.
I'm going to add a new layer too.
So we don't have any conflicts.
We'll call this bouncing jump back onto the bouncing tarmac.
So we're doing this all at the tile map level.
So everything that we apply to the tile map will have these particular rules, including the bouncing.
This will do in a moment.
So I'll change the layer here to bouncing and that should be all pretty cool.
Let's just check that that's working, that the player can run and at least collide with the mushroom
over there.
Jump, jump, jump, jump.
Yep.
I can collide and I can land on it.
Can't jump off the mushroom because we haven't created that logic in our code.
That's fine.
I think this will only be for bouncing.
I don't see a time where we need to actually jump on it because as soon as we touch it, it's going
to go boing and push us way off into the distance.
Now the next step I'm going to, let's say, my assets folder.
Where shall we put this?
I'm going to create a new folder, right click create folder.
We'll call this materials double clicking materials, right click create a 2D Physics material, 2D.
And I will name this bouncy bounce just to be very professional with my naming.
Now you can see if you haven't played around with physics materials before, we've got these two values
friction and bouncing.
This friction we'll get to later.
Bouncing us is going to show how much we bounce off there.
If it's zero, there'll be no bounce.
That's zero on there at the moment.
So I'm going to put this to say 1.5.
So we have a value at one.
It means that if we drop from a certain height, we should bounce back up to that same height.
But if it's 1.5, if we drop from that height, we should bounce up 50% higher.
I think that's going to work out the maths on that might not be exact, but I know that a value over
one is going to have us go jumping higher and a value under one is going to have us go lower.
So I'll put that at 1.5.
Click back on the bouncing tile map.
Now we need to find the right spot.
There's a couple of spots in here that ask for material so you can see on the tile map.
Collider Also on Rigid Body, it asks for a material also on the composite.
Collider I'm going to put this one on the tile map.
Collider 2D.
So if that works, cross our fingers, hope for the best.
Click on play.
That's often how game development is, isn't it?
Just try things, see if it works.
Jump and boing.
That's a nice bounce.
Excellent.
So the cool thing about this is if I didn't jump on the mushroom, I can't actually escape here.
I can at the moment because we've got this dodgy wall climb thing, a double jump thing.
But I need to actually use the mushroom to bounce out of the hole in there.
So we've got ourselves another game mechanic, which is really neat.
I mean, you fly a little bit too far and if you stay on it, you go a little bit crazy.
But that could be fun in your game if you want to do that.
And the trick there is to play around with the value.
So if you don't want it to be quite so bounce that bounce and get more and more, then you can put it
closer to one.
But for now that's fine with me.
You can jump on the mushroom to escape that pit that we're in.
Excellent.
So that's the first part of using physics material.
2D, I've got these mushrooms, you can have different sorts of things.
Remember, with this particular approach, this approach that I've shown you here, all anything we
put on this time map will have the same 1.5 bouncing ness.
So with this particular strategy, you couldn't have big mushrooms that make you fly a long way, little
mushrooms that make you fly a smaller way.
You'd need to have separate tile maps to do that if you're going to do that particular approach.
Of course, if you wanted to have something that was a different bouncing profile, you could go and
create a game object and put that into the world and have that have a different bounce profile.
So you could have a bunch of different game objects.
But we're trying to do this all within tile maps at all lines up nicely and works with the tile map
structure.
Next up, what we're going to do is stop the behaviour where the player is gripping to the wall.
This is also a physics material issue.
So at the moment I can go jump, jump, jump, jump, jump, jump, jump, jump, jump.
And I'm grabbing onto the wall.
I don't want that.
You might want to have wall jumps in your game and that's cool.
You can play around with that.
But for me, I want to have it.
So I don't actually I don't actually stick to the wall.
I don't get stuck like this.
This is the main thing I'm trying to stop being able to do.
So this is a challenge for you to play with friction.
Stop the player from gripping to the walls by applying a new physics material 2D to the player.
So pause the video.
Take that on.
See you back here when you're done.
Okay.
This one should be reasonably quick, I think.
Well, in our materials folder, right click create two dx physics material two dx I'll call this friction
should probably be called no friction.
No friction.
That would be a smarter name, wouldn't it?
Rick Yes, it would.
Rick okay.
Talking to yourself, first sign of insanity, friction.
I'm going to put to zero bouncing us.
I'll leave at zero as well, then click on the player.
Where do we want to put this?
Probably on the capsule.
Collider I think we've got our material here.
I'll click on the selector, no friction, click on play.
And if we don't do the stuck to the wall running thing, mission accomplished.
Yep.
Awesome.
So I'm pushing left, but I'm not sticking.
I can still do the extra wall jump.
That's something we're going to fix in the next video, but for now, we've got it.
So the player is sliding down the walls instead of accidentally gripping, getting stuck.
And we've also made ourselves a fun, little bouncy mushroom kind of thing to add an extra gameplay
mechanic into our game.
There we go.
I'll see you in the next lecture.