In this lecture, we're going to play around a little bit with our Sprite shape.
We're going to make our snow look a little bit better and we're going to add an edge collider so that
we can start to use Unity's physics system to make things roll down hills.
Okay, let's get started.
First thing I'll do here is to move my sprite shape.
So I'm going to click on my Sprite shape at this level, hit W on the keyboard and just move it to the
start of the level.
So you can see here where the camera is, the camera is at the origin 000.
So it makes sense to have my level start at zero zero and I'll just position my world so that it fits
roughly where I want it to be with the camera.
Okay, round about there.
It's good.
Okay, so what we're going to do here is add an edge collider.
So click on your level, sprite shape and scroll on down, find add component and we're going to search
for Edge Collider two DX Click and then bump straight away.
You'll see that has added a collider all the way along our sprite sheet, which for me is Magic Collision
has already been added.
So you can go and modify this, click on the sprite shape, click on edit spline.
I could go and move any of these nodes and the collision flows along as well.
That's such a powerful thing to know when it comes to making platformers or making shapes or making
any sort of product as well.
This is this is huge.
I love it.
Now, what I want to do next is add a ball at a circle that can roll down this particular hill so I
can roll along in our level.
I'm going to give that to you as a quick challenge is to make a ball roll down the hill.
I'm not going to give you any more information, see if you can figure it out from there.
So that is a challenge.
Pause video.
Take that on.
See you back here when you're done.
Okay.
Now, if you jumped over into your hierarchy and right click and created a 2D object, then you're in
the right ballpark for sure.
If you clicked on sprites, excellent.
Now if you went and said sprite circle and then add a rigid body to that, add a collider to that,
that's perfect.
That's a great way of going about doing it.
I'm going to show you something slightly different.
If you look at physics, you'll see that we have what is called a dynamic sprite.
If I create a dynamic sprite, just going to rename it from dynamic sprite to B say ball.
It comes already attached with some cool things.
It already has a circle collider and already has a rigid body 2D.
So we don't need to go and add those things.
It's ready to be a physics thing.
I'm just going to line it up in my scene view so that it matches what I can see in my camera view.
I could move my camera to that spot.
I'm just going to move the ball to the start just here.
Okay.
Now, it's important to make sure that it's dynamic.
Yes.
On the rigid body type.
That's important.
It's also important to make sure that we've got some gravity on.
Yep, that's cool.
So when I click on play, everything else should take care of itself.
The ball just drops to the ground bonk and then roll, roll, roll.
You see, my screen went big just now because I've still got maximize on play clicked on for some reason.
So in my game window I might need to scroll over here, find maximize on play.
I'm going to turn that off.
But obviously if you wanted to have your game take up the full screen, you're going to have a maximize
on play turned on.
I can turn it off for now and then just do that one more time.
Click on play and my ball is going to roll using gravity and using its physics system.
Excellent roll or roll, but you can see there's a problem.
We've got a little bit of a gap between where the ball is and where our world is because our edge collider
is above where our snow wants to be.
How do we address that?
Well, to be honest, it took me ages and ages and ages to track this down when I was wrestling with
why this is the case.
But the fix is incredibly simple.
Click on your level, sprite shape and then under Collider you can see an offset.
We want to change that offset.
I'm going to drag it down.
You can do it wherever you want.
I'm going to drag it down to be just a little bit within the snow roundabout.
For me, it's a 0.31 when I click on play.
Now, the ball should look like it's in the snow, touching it properly, yet rolling along the snow.
That's what we want.
Now, another thing we'll do while we're here is just have a look at the scaling of this amount of snow
versus all of the blue.
I think I want some more snow.
So what I'm saying is I want my tile to be larger.
And the way that we do this is a little bit trickier.
But I'm going to scroll out, scroll out so that I can see all of my level, click on my level, sprite
shape, click on edit spline drag to select all of the dots, all of the points.
And now in here you can see we've got something called height.
And if I increase the height, it will make all of my snow look bigger and or I can drag it the other
way and make it smaller.
So drag it to the point where I think it looks pretty good around about there.
I think, yeah, that's not too bad in relation to ball and snow and blue and all that kind of jazz.
Now when I scroll back in, let's see if it has retained on a double click on my ball to zoom right
into the ball, then I'll click back on my sprite shape again.
Yeah, it's retained the placement for where our collision is relative to the outside of the sprite
shape.
I can move my ball just a little bit above to make sure it's not touching the thing.
Cool.
So there we go.
So I've just made it look a little bit nicer now.
One thing I skipped over quickly because I gave you assets already that were already cut up nicely.
But if you look at this snow tile, you can see in our little preview here, it's got a curve on the
end of it to say, well, we could have this as an end point, but in our world we don't see that curve.
That's because I've already edited it in the Sprite editor, so I want to show you that process.
In case you're using any other particular shape, you click on Sprite editor and you can see in here
we've got these green lines.
So I've already said for this one graphic I'm using, I want the shape that we're using for our particular
Sprite shape is to go from here down to here.
Hopefully you can see those green lines in there.
If I was to move that, I could say, well, maybe I want it to go from there all the way to there and
then click on Apply.
And now when we go back into our into our scene, you can see that the curves have been captured and
it doesn't tile in a very nice way at all, does it?
So that's an important thing for us to note.
I'm going to go back into my Sprite editor's click on my Snow Tile Sprite editor and then I'm just going
to put this just a little bit past where the curve is, just there a little bit past where the curve
is just here.
So we could have done this when we're placing it down.
But I just wanted to point that out.
Now that we need to do that, if you've got anything else you're bringing in, the other thing you might
be wrestling with is if your fill isn't texturing properly, particularly if you've brought in your
own asset for this as well.
And I totally encourage you to use different assets to what I'm using.
So if you click on the Blue Fill need to make sure that where it says the wrap mode we have wrap mode
is repeat.
If you have wrap motors clamp, it might give you some weird looking artifacts, particularly if your
fill isn't just one color minus just one color.
So it can't really go wrong no matter how.
Raps or how it repeats.
But here in rap mode, I've got repeat and it's the same if I click on my sprite tile for the snow in
here we have repeat as well.
So just want to point those things out.
I really encourage you to go add your own assets to this so it looks different.
And in this lecture we've gone and added an edge collider so that we can get that whole physics dynamic
and use our sprite shape as our world that our snowboarder is going to be cruising around on.
So good stuff.
I'll see you in the next lecture.