In this show, we're setting up our rule tile rules, which is going to be super exciting.
It's going to allow us to paint things into our world, to use rules, to say what tile should be placed
in what particular square so that it looks nice and lovely.
So let's get started.
First step we need to go to package manager and search within the Unity Registry.
Make sure you're selected on that.
Might take a moment for it to think.
Yep.
Then it's cool.
Search for tile.
If you see in here tile map extras.
That's where we can find the rule tile.
I'm going to click install on that.
It's kind of hiding over the edge a little bit.
The install button.
Now in the future, you might not need to install this.
It might come standard with unity, but for now you need to do that.
If you're not finding it, particularly if you're using an older version of unity, you might need to
click on the cog, go to advanced project settings and enable the prerelease packages.
Sometimes when the packages are still having the bugs ironed out of them, you need to go and enable
that.
But now we've installed that.
What I can do is back onto my scene in my sprites folder.
I'm going to right click and create 2D tiles and then you'll see now we've got rule tile that drops
a rule tile in here.
I'm going to rename that just simply rule tile.
I'm just going to have one in my scene.
So I don't need to give it anything more fancy than just calling it rule tile.
Why have I got this in my sprites folder and not my tiles folder?
Well, I'm going to be doing a lot of backwards and forwards with this particular sprite sheet in here.
And so I want to have easy access to this rule tile, but in the sprites folder just means things are
next to each other, which is handy.
Now I need to actually place the rule tile on my palette so that I can use it in my world.
I can't just click on this in my project directory and start trying to paint it around.
It needs to be on a pallet and to do that I'm going to put it on the platform's palette.
But you could, if you wanted to create a new palette that is just the rule tiles palette.
If you wanted to do that, if you wanted to know exactly where it is.
But I find switching between the palettes is a little bit of a pain.
When you've got a small project like this, I'm just going to grab the rule tile and drop it right at
the top and it looks like we've got something a little bit buggy that's got introduced into there.
That's fine.
We won't worry about the bug at the moment.
Thank you.
Unity for your bug.
We've got our rule tile but I dropped it in but I can't see it.
It's not in there.
It's invisible.
That's because we haven't given it a default sprite.
So make sure you clicked on rule tile from down in your directory and then over on the inspector you
can see we've got this default sprite, you can click the select button or you can just go to where
you know the assets are and find what you want to have as the overall look for this and the default.
If no other rules apply, then apply this one.
It's going to grab one of my green grass, drop it into that little area there.
Now our our rule tile has a look to it and blink in our palette.
You can see that it appears if I click on the rule tile from the palette, jump over into my scene anywhere
in here and just paint this down.
You can see it's painting that one default tile that I've got.
So once again, make sure you clicked on your rule tile over in the inspector.
You can see that the tiling rules, the list is empty.
This is where we're going to give logic to the rule tile click.
Plus, we'll put in our first piece of logic, which will be, let's see, I'm going to find my empty
kind of in the middle of things tile, which is this one in here.
Also, if I show you my sprite sheet, it's this just plain color in there.
I'm going to click and drag that over the top of the selection.
And now you can see everything has changed color.
So what do we want to do?
Well, we want to have this tile be present when it's surrounded.
So my little example in the palette over here, you can see that we've got something on the outside
of this one tile just in the middle here.
Let me click on that.
This tile here, we've got something there, something there, something there and so on.
So overall now rule tiles, you can click in the little grid and you can get an arrow which says, yes,
there is something in that space.
So you can see the arrows in the top left corner.
That means that there yes, there would be another adjacent tile on the top left corner.
Or you can turn that into an X that says, no, there can't be anything there.
If there is no tile there, then this rule becomes valid.
So what I'll do is just put an arrow all the way around the outside.
Later on we'll see that we don't need these corner ones.
But for now, let's do what makes sense.
And it says if there's something surrounding this tile, then hey presto, this is the tile that it
becomes.
Just click back on the rule tile and if I go and paint up the top pair, you can see it's magically
changing.
What happens?
It's saying, Oh, I think you want to have this particular tile based upon your rules.
Okay, let's set up another thing.
We'll do the corner.
We'll do the top left corner, which corresponds to this particular tile up here.
You can see we've got the corner in the top left is different at the corner in the bottom left, you
could just do the same.
But this top, the bit you jump on looks a little bit different.
It's a bit more faded down the bottom.
So we've got a top left and a bottom left.
We've got these side ones, got the top ones, and all these ones here that have a solid edge on the
left and the right is when you just have a single tile poking up in the air.
Likewise this these ones are when you just have a single part tile poking left and right.
So let's click on plus add a new rule and this new rule.
What do we want the tile to be?
Well, let's find.
The very first one here, the top left corner dragged that on over.
What are the rules for the top left corner?
Let's have a think about that.
So this top left corner here, there's no tile there.
There's no tile there.
That's a little bit misleading.
As my cursor pretends there's a tile.
Let me click on something that's not a tile.
There we go.
Nothing there, nothing there, nothing there.
So let's go and put an X in the top left, an x right above and an x right to the left of it or left
to the right of it.
And then we do have a tile to the right, a tile to the bottom right and a tile below.
So we'll put an arrow and arrow and arrow.
Now there's not a tile here, but there might be.
So in that instance we'll leave it blank because I'm not sure yet.
Maybe if we were to paint a tile there, we still want this to be a corner.
So if it's a doesn't matter whether there's a tile here or not, then you just leave it blank.
As I've done there.
Click back on the tile and make sure this works okay.
Yeah.
You can see as I paint one there, it currently doesn't have a tile to the right of it.
That's why it's staying in that default shape.
But as soon as I put a tile to the right, the rules apply.
You've got nothing left, left, left, and you've got something.
Right, right, right.
So the right and the bottom.
Right and the bottom.
Now, something cool that we can do here instead of having to go through our whole flippy sequence we
did last time.
Which side note it seems to have broken itself.
I'm not sure why.
Might need to go in and reapply that because it's misbehaving.
But I don't need to do that at the moment.
We're going to transition in and rule tile.
So most of this what we can do over here and say, well, this same rule I want to apply if this is
in the top right as well so I can click on the rotation.
So right in the middle you see there's a little gray symbol, it's a dot, then it goes to a curved
arrow, a left or right arrow and up B down arrow, and then the up B downy and lefty right together.
So the dot means just keep it as is the curve.
Arrow means rotate.
That means rotate 90 degrees, 99 degrees.
So to do that the entire way around now you can see by doing that, we've got top left.
Just click off this again.
Top left is a corner.
Top right is a corner.
Also, if we go down the bottom here and say bottom left is a corner and bottom right is a corner,
because that's what happens when you rotate it.
You can get all this power just by adding one tile.
You don't need to add all these rules all over again because it's rotating what the rules are as well.
Now, I don't want it to apply to the bottom left and bottom right because we've got the this bottom
corner.
So in this instance, I'm going to do just a mirror on the x axis.
If I was to click it again, it'd be mirror on the y axis, click it again, it'll be mirror on the
X and Y and back to the dot.
So just on the x axis, that means it's applying to the top of our corners.
Now let's apply the bottom.
So click on the plus again ad and then we will find what is the bottom left.
I think this is the bottom left corner just here looking like that.
So just a reminder that one just there you're looking for from your tile set, if you're using the same
tile set as me, that is drag that on over.
Now I will say what the rules are.
Once again, we'll hop in here and find it.
Well, there's nothing in these bottom pieces.
So X, x, x, and then there is in the ones adjacent to it in the top, top, right and right.
That should make our corners.
Yeah.
And then we'll do mirror on the X once again.
That means over there it should be valid.
If I jump in and just click on the rule tile, do a little bit of painting around.
Yeah, it looks like it's all behaving itself pretty well.
What's not behaving itself well just yet is you can see our bottom is not working, so we need to be
applying the bottom tile.
Our right isn't working, our lift isn't working and our top is well.
It's kind of working, but not the way we want it to because it's just applying this green single square
one.
I think I might want to have a little bit of random.
So it's sometimes green and sometimes blue because I've got both of those tiles in my tile set when
we've just got this long flat platform.
Let's see if we can figure that out.
How to do some randomness.
So we'll click.
Plus again, I want to add a tile.
This time we will change from output from single to random and in random.
How many of these do we have?
We've got one, two, three green pieces and we've got one, two of the blue pieces.
So I'm going to change this to be five in terms of how many things we have.
And you can see when we put it in there, it's got a whole bunch of blank spaces because it's randomly
choosing between this rock and nothing.
So let's go and grab in our other sprites, the other green sprites, one, two, three, and then a
couple of blue sprites, one and two.
Now they should all be filled in.
So sometimes they're going to be green, sometimes they're going to be blue.
You can do a little bit of additional randomness.
So we could mirror on the X, which will make these tiles flip, which is kind of interesting to do.
You can mirror them on the Y, which you don't really want to do.
It makes them upside down.
But if you wanted to get a whole bunch of additional randomness and variability in there, that's a
cool thing to do.
So we've got that our tiles are being placed in.
Let's just see if we can draw a bunch and see if we get this random inverse.
Random.
Yeah.
So we got a little bit of random.
They're green, blue, blue, green, green, blue.
Because we've got three greens and two blues.
There'll be a little bit more green, but that's okay.
There's a little bit of grass growing in our world and it's happening in a round.
Way, which I quite like.
Now we need the rules for this.
Okay, so what's the rule?
Well, when it's a top title, they'll definitely be nothing right above it.
So an X there, there is going to be something below it.
So that's pretty much all we need for the titles.
Now, is there something to the left, maybe something to the left there?
Maybe not sure yet.
We'll figure that out as we go.
As we add in more titles, you can see it's a little bit broken over here.
So maybe we do need to add something saying that.
Yes, there's something to the left.
Yes, there's something to the right.
Okay.
It's nearly there.
Oh, we don't have our side pieces yet.
That's why it's looking a little bit funky.
Our default piece is, is that grass that's white looking a little bit weird, but we're making good
progress and we've still got a bunch more rules to set up.
So I'm going to give this to you as a challenge to finish your rule tiles, finish setting up your rule
tiles so that all the shapes and positions work and look good.
And using your rule tiles create a couple of simple platformer layouts, just a couple of jumps and
a couple of gaps to jump over to show that it all works.
Maybe some single things up in the air.
What I mean by that, they're the tricky ones.
So a couple of these single things and a couple of single sideways things as well to make sure you get
the top and the bottom on that.
And just one quick thing before we start our challenge.
The order that things appear in the list is the priority that they're given.
So whatever is at the top will be the rule that's enacted first.
So if you find that things aren't quite lining up, try dragging things up and down in the order just
to see if that changes it.
Putting it as a higher priority might fix whatever troubles you are having.
Okay, so jumping into the challenge, see you back here when you're done.
Okay.
Welcome back.
I've gone ahead and created all my rule tiles.
Now, what I've found in the past is that people say to me, Oh, he went so quick through the rule
tiles, what were they?
How did you do them?
And so what I've done is created a little screenshot here of my rule tile rules.
I've given this to you as a jpeg.
So this particular image here, so you can go through and see exactly what I've done.
You can see what the rule tiles are.
If you want to do this just on the video, then I'll hold it on that bit.
You can pause and then we'll go down to this bit.
You can pause and have a look at that and check what I've done, and then I'll jump down here and you
can pause again.
I think that captures it all.
Just to note, there's a couple of places where you don't have to do randomness, but I did so I did
some randomness on Let's See, on our flat with the grass top.
We talked about that already in the video.
I did some randomness on the bottom, randomness on the left, because these are things that I had multiple
assets for.
So I just drop those in so that we could do that.
And also a little bit of randomness on the overall tile here, the middle tile in the middle.
I just randomize between the straight up solid color and the solid color with the bumps on it.
If you play around with a noise that just changes where the randomness appears, you can get some different
looks if you like.
Oh, that look wasn't quite right for me.
Then you can play around with the noise to get some different looks there.
Some other things I'll note is that I needed to drag up to the top.
Let me get my image back for you so it's easier to see needed to drag all the way up to the top.
This corner piece I found that made the most sense in terms of having that rounded corner piece actually
show up that corner piece.
I mean, is this one just in here, this rounded edge piece in here?
I had to do a lot of drawing.
What happens when I go up like that?
Because there's a whole bunch of these rules for if you have something just sitting on its own and you
can see this is the sitting on.
So there's Xs all around the outside.
What happens if something is just sticking out from the side like that?
That's this piece just here with the Xs and the arrow.
I've mirrored on the x axis for these ones.
So that you see the same thing appears when we have it over on the right.
Also, what happens if we have something sticking out of the top?
That's this one here.
And similarly, if we have just a pillar rising up in the air, that is that one here as well.
Likewise the pillar on the horizontal.
So we've got those things there.
The one that I've got right down the bottom is this kind of middle padding stuff.
Once you make a box all the way around the outside, then this one right in the middle here is going
to be the catch all rule.
Catch them right down the bottom.
I think that's most of what I did in terms of the changes.
A couple of little tweaks I put in this piece here, which is the has the solid top.
Then just a couple of dots because I was finding there are a couple of places where we needed that.
Where did that show up?
Oh, there we go.
This is this bit over here.
So when I have just that little square in there, there's nothing above it.
There's something to the right, there's something on the left, something below than I needed to have
this particular tile in there.
If I didn't have that, then it went a little bit weird.
Or if that was dragged all the way down to the bottom, then it just placed in that weird, just straight
up flat tile at the top.
So I put this all the way second from the top.
Now that gives that priority over our other rule, which is just our flat top platform rule.
So there we go.
That's all my rules.
I'll give you that as a downloadable so you can see the image.
You can also go to our repo for any of our lectures.
Just a reminder and you can go and download or grab or clone this specific commit that I've made where
I'll have all of my rules.
So hopefully you've found that a fun experience.
I love the fact that we can just slap down our platforms however we like, and I will see you in the
next lecture.