Welcome back, my fellow game developers.
This video will be a bit longer because this is
one of the times that I
really wasn't sure what we are going to make.
So I wasn't sure if I wanted to make
this a trigger or I wanted to make this a solid object.
But anyways, when we walk through
this, but nothing happens,
but if we dashed through it,
you can see that we can break it. How cool is that?
And it disappears on its own after a couple of seconds.
So let's not waste any more time.
Make sure to put your concentration SCAP on.
I do have teeny tiny mistakes
and some hesitations during this,
but don't worry, I explained
everything as much as possible.
So Let's get started.
Oh, okay, So now it's
time to add a couple of breakable objects.
This is the whole point of the section.
We're at the second video and we
still haven't added anything to destroy.
So I'm going to go into my sprites in here.
And I'm going to make this slightly bigger.
On this way. I guess we can even
make these icons are a bit smaller so they fit nicely.
There we go. So I'm going to
right-click create a new folder,
and this will be the breakable objects.
Breakable objects,
and this is why we always create folders.
Imagine if we had all of
the sprites altogether in a single folder,
it would have been a nightmare.
Anyways, we'll go into the resources,
as you can see right here,
we have many bots to destroy.
I'm going to choose the right one.
I'm going to choose the white breakable object.
There we go.
We sudden in here.
And we can go ahead and dissect this.
So I'm going to make sure that it's multiple.
And I'm going to do this may be off
screen and I will let you know when I finish.
Okay.
So welcome back.
Let me tell you what I did.
I didn't want to bore you with
all the details, so all I did,
I sliced up 32 by 32 the white box.
We have three different parts here and
three different breaks are used.
The W1, W2, and W3 to describe the biggest pop breaking.
And I make sure that we have
these little three pieces in here.
They will come in handy later on.
So I'm going to discard any changes.
I also created an animation for the bikeable parts.
So there you go, you can see it breaks up.
We're going to make sure from
now that we go to the breakable.
So you can see white bought breaking,
make sure it doesn't loop.
We are going to save all of that.
Now the braking pot,
I'm going to add a year
Box Collider or a circular plus no,
not a canvas. Remove the component.
I'm going to add a box collider.
So box collider 2D.
There we go around this,
I'm going to make it a bit smaller.
I make the pixel size on the sprite.
Let me show you what I did also.
So you don't get confused.
You can see that the pot is
around a good size for the player.
Let's keep it that way.
And what we can do is we can go ahead and make it,
well, this will depend on you.
Do you want your object to be able to
want us to be able to collide with this object,
or we want to just make it a trigger.
I'm going to keep it a trigger for now,
later on, if you want to change this,
if you want to have interactions with the pots,
you want them to stop you from walking through them.
Than I do recommend you make it non-trigger.
Know what, Let's keep it as a non-trigger.
And for that reason we're going to add
a rigid body to it and we'll make it static.
Okay?
So it's a static. It does not move,
but we can break it.
So what else should we be doing in here?
Well, I think that's it. For now.
Let's save this and let's
go ahead and add a script to it,
which is going to be called the breakup bulls.
So in the scripts,
because we want to add behavior obviously
to the spot we wanted to break.
Come on, okay, so let's see enemies player UI,
and let's go ahead and create a folder in here.
And let's make it for the breakable.
Break bubbles opens up right-click Create will probably
not have a different script
or another script, okay, so breakable.
But the good thing about creating a folder and setting
just one script in here
that we can see it from the outside.
So and scripts right here,
we can go ahead and check the
breakable so we can find it immediately.
I'm going to add to the braking part. There we go.
We have the break bubbles.
Let's open this up in here.
And what shall we be doing?
Well, because we are not using a trigger,
we're going to use something called
the on collision enter.
So there you can see on collision is when
the colliders less rigid body has begun
touching another collider or rigid body,
and we'll make sure that it's 2D.
So in here you can see that instead of other,
we have the collision.
So what we're going to do is we're going to check
if the collision.com tag,
does it have compared tag? Nope, it doesn't.
Tag.
Or we can access the collider.com tag.
There we go. So now we have
the collider of the collision.
And we'll check if it's the player.
And if it is, then we are going to
destroy the game object.
Excuse me, the game object.
Save that.
And we'll also go in here,
check for the animator
and see what kind of trigger it does.
So we'll need to create an idol in here.
So we'll go into the assets animations.
Or is it, where is it?
Where is it? Breakable?
White part, idle.
That means that it's not moving
because obviously you can see we
don't want to have it
breaking as soon as we start the game,
we want to keep it like that.
So what we can do is right-click in here
and set this as the default state. So there you go.
And we'll add this right here.
Create a transition which will have some kind of trigger,
which is the break,
Scott break for simplicity,
no exit time, transition duration 0.
And I'm going to go ahead and make it as the break.
Then we'll go back in here.
We are going to,
because this is, this won't be too complicated.
I'll just get the animator immediately.
So in here I'm going to say if the collision
as player before we destroy or actually,
you know, we are going to remove this.
I'm going to go ahead and get
the component, the animator.
And in tor dot set trigger and is going to be the rake.
And I know it's a string reference and I didn't copy it,
but I hope the break is easy to understand.
And then I'm going to create a public void.
Destroy.
Well, no, destroy.
Just, let's just call it destroys.
And maybe we want to add some kind of
cold in so we don't want the pot to be destroyed.
So let me tell you what I'm looking in here to do.
What without a coroutine,
simply destroy the game object.
What I wanted to say, I wanted to
use a co-routine to delay
the disappearance of the little pieces right here.
But on the other hand, I thought it might be even better
to just set this right here,
called the event after maybe a couple of seconds,
or we can choose maybe on second three,
go, set the event.
What's the function? Destroy, save that, run the game.
So now we should see that as
soon as we collide with the pot,
then it gets destroyed.
And there we go,
the object has disappeared.
And what we also can do is, for example,
we can go in the animation of
the braking part and the animation.
So as soon as the pot breaks,
Let's say it shatters right here.
What we can do, we can start recording
and then turn off the box collider.
So you'll see that right now the box is good when you
see the pot entirely and when it breaks, there we go.
There is no more collider.
And if we look closely,
we can choose the collider and maybe move it a little
bit before it actually breaks.
So it seems as if we've walked through it.
So save that. Run the game. Oh, no. Talk.
No.
Not like that.
Sorry.
Oh, so it record I
forgot to press the right button. We run the game.
We had the pot.
There you go at breaks.
So it feels really as if we walked
through it and you can see the pop disappearing.
Okay, great.
So what that done,
what we need to do is we need to make
sure that this pot breaks,
not when we are just walking through it,
we want it to break when we actually dash through it.
And I think that this is going to be a challenge for you.
And your challenge is going to be to
return a Boolean value.
What I felt that was about breaking when we're running,
well, when we are dashing,
we want to create
a method int player controller that
we can access from the break we'll script.
Why is that?
Well, we'll need to create a method that
returns a bool instead of a void.
And that method should return
true if we are dashing and false,
if we are not and false if not,
not, this is not w, it's steep.
Hence, we will need to use the players,
the velocity or the player's move speed
or whatever you want to use.
So why are we creating this return value?
Because in the break bubbles,
we want to make sure that the player is actually dashing.
So we will add to
the condition in the on collision enter.
We want to make sure that it's not just the layer.
We want to make sure that it's the player
dashing that just hit our pot.
So that information create
the method that will return a Boolean value.
Pause the video right now.
Go do the challenge. Go do your best.
I know we haven't done this type of
method which returns something other than void.
But I know you are up to just try to do your best.
Okay, welcome back.
I hope that wasn't too hard.
I'm going to go into the layer controller.
Okay, so what is the problem in here?
You might say that, Well actually,
I just want to access the current movement.
And I can immediately know
what the speed of the player is.
But in here you can see that
the current movement is private.
So what we'll need to do as we are going to
create a method in here.
And that method is going to be
a public bool layer is dashing.
And what are we doing in here?
We are going to check if
the current movement speed is equal to the dash speed.
We could have also used the candle,
but they can dash isn't equivalent.
Where is it?
Where are we resetting the numerator.
So he can dash is not
equivalent to when the movement speed stops.
So we can dash is just to cool down the dashing
while the movement speed is
immediately related to the dashed length.
So back in here,
if the current speed is equal to the dash speed,
we are going to return true.
Else we are going to return false.
And by the way, we could have
done something similar to this,
so I can remove these.
And as you can see, it's much cleaner.
Why? Because we only have one line of
code under the if and else statements.
Otherwise we could not have used this way.
Now we have it as public.
We go back to the breakable.
We are going to go ahead and
create a Boolean inside of year 4.
We destroy the pot after we check for the collision,
obviously because we don't want to
always know what the player speed
unless it's the actual player collided with, just hit.
So I'm going to go ahead and create a bool.
And it's going to be layer is dashing.
And it's going to be equal to
the collision dot game object dot get component.
So it's a bit different than when we are using a trigger.
And in here we are going to simply
get the player controller.
And we are going to check if
the layer is dashing, save that.
So now this should either return true or false.
And in here we're going to check if the layer is dashing.
Then we are going to start the animation.
And when the animation starts at
breaks and destroy stick game object eventually.
So one thing that I wanted to
mention here is in here we used collider.
In here we use the game object.
We could have used the game object in here, save that,
and it would have worked the same,
but the collision, you can see right here,
it returns a collision.
It doesn't have the certain,
Let's say methods that we need.
So if I go for example,
and on the other place,
so level exit for example, in here,
the collider 2D is different than the collision 2D.
So collision is part of
the detailed return to the physics.
If we look in the level exit,
the collider 2D actually returns the game objects
so we can immediately access
the tag while when it comes to the collision,
It's just a little bit different.
I recommend that you go through Unity's documentation,
see what the difference between collision collider.
These are small things,
but just know that we are accessing
the game object first and then using the compare tack.
With that out of the way,
let's save all of this.
Let's go back into our game.
Let's run the game.
Let's try to break the patois walking.
Okay, there you go. So it's not breaking.
And if I tried to dash,
oops, I forgot the bottom two dash.
If I dash. Okay.
It's also not working.
Why is that?
Okay, so it broke. There you go.
Let's try this one more time because
there is something that was a bit slow.
And I believe the problem is with the game.
Wait for a second.
So I think I want to move this,
the thing that handles the collider.
I want to move it to the beginning.
Save that because I want the collider to
disappear as soon as we start breaking the buck.
So there we go.
You can see right now that we can simply move through.
Now if you want to add a bit more,
maybe I don't know authenticity
that we want to keep it just a
teeny tiny second before we
go ahead and break it, It's your choice.
Make sure that you choose whatever you want.
Let me see.
Okay, so if I want to move,
if you move just the breakable pot,
choose the second line.
There you go and you can see that you can move it.
So save that.
Now we have everything working.
Let's try to walk through it.
It won't work. We walked through.
It doesn't work with dash through it, it breaks.
Great.
Let's go and make sure that we stage everything.
And in the next video,
we want to show the broken pieces of our pot.
So we want to have some kind of pieces that spread.
That's why I created and the sprites in
receivables here we have the P1, P2, and P3.
These are pieces that are
going to lay around this and they
will add a bit more of a feeling of pots breaking.
So we want to have pieces flying around
a bit and then disappear slowly,
making things a bit more authentic,
a bit less rigid.
So I'll see you then.