Hello guys.
Welcome to the video.
In this one we're going to make another enemy.
It's going to be enemy Reddish.
This one is quite tricky but at the same time a very simple one.
If we open the graphics we can see that this one has an idle.
If we open this spreadsheet, we can see it has sort of a flying animation, because this one has this
little leaves over here and it's spinning like a propeller.
Yeah.
And then there is this idol.
Over here without leaves, and in this one he is supposed to walk on the ground.
Also, it has running animation over here, so I think it's going to be a pretty fun anime to make.
The lodge are going to be a very simple, uh, it's going to fly in the air somewhere here.
If you jump on the head of this enemy, he's going to fall to the ground.
He's going to walk, do a circle, come back to the position he had, and then fly up to the position
he had.
That's what I want to do.
Uh, let's delete extra bees and let's do prefab and park completely.
Is going to be reddish.
Now we're going to take Idle Sprite from here and drag it to Sprite Renderer.
Like that.
And let's make pixel per unit.
16.
And let's remove enemy B.
Let's go to scripts folder enemies and let's make a script enemy reddish.
Going to put it on the game object.
A.
What's up?
Like that.
Very nice.
Love it.
Uh, we need animator, so let's go to Asset Animations.
Enemy.
And I think I can copy animator.
Controller of the mushroom.
Let me copy this.
Go to enemies, make a folder for radish.
Go inside of this folder, paste the scene, and let's rename this to Enemy Radish.
I'm doing this because this one has a bunch of a setup that we can use on enemy radish.
Let's drag it here.
Let's go to animator and let's just see it, okay?
This is almost everything that we need.
Uh, we're going to just transfer to heat from any state.
With a heat trigger.
Can transit to self uncheck.
Let's delete this transition over here.
And let's go ahead and create animations for this because this is using the animations from mushroom.
Let's go to animations enemy radish.
Uh.
I'm sorry.
I need to be sure I did not mess up the mushroom itself.
This one is here.
Should be fine.
Okay.
And let's do create new clip.
Enemy.
Uh, sorry.
Make sure you select enemy reddish.
And let's do create new clip.
Enemy reddish.
Idol.
I'm going to go to graphics.
Enemies.
Uh, reddish.
The second idol we're going to use now.
Sample rate.
20.
Let's double check it.
Yeah.
This is the one where he stands.
Okay, let's go and create new clip.
Enemy radish.
Move!
I'm going to take the run sprites.
Take them.
Drag them here.
Separate 20.
Then let's make one more.
Enemy radish lie idle.
And over here.
We need to take idle from the first one.
Going to drag it here.
Sample rate 20.
And we need enemy reddish heat.
Enemy reddish heat.
December 8th 20.
And we're going to take these sprites over here and drag them here.
Okay.
Now, before I forget, let's go to Asset Animations.
Enemies.
Reddish.
Let's take the hit and uncheck loop time.
Now we need to set up these things over here.
Uh, we can take enemy hit here and just drag this enemy reddish heat to this field.
And now we do need this animation over here because it is in this, um, uh, animation state.
Right there is the motion.
Uh, also, we can remove idol and move.
We can go inside of this blend tree and assign them over here.
This is idol.
Sorry.
Enemies.
How did this happen?
Reddish.
Yeah.
Um.
Idol.
Move.
Okay.
This is good.
Now let me go back and double check the heat.
Yeah, this is fine.
And now we have this fly.
We're going to make another boolean.
Play.
Uh, is flying.
Is better.
Is flying.
And we're going to just transfer to this is flying if it's a true.
And check exit time transition duration zero.
And then we're going to transfer to fly animation if is flying is true.
Then we're going to transfer back.
If is flying is false.
Zero and check exit time.
Nice animator is ready and let's go inside of the script.
Let's inherit from the enemy.
And then I guess we can just take the logic from the mushroom.
Let's take this logic from here.
Go to enemy radish, paste it in.
I'm going to do close all but this.
And now it's supposed to work as it is.
And we only need to add functionality where enemy flies up or falls down, walks and then flies up.
That's what we need to do.
Before we do that though, let's go and make sure it is working right now.
Going to go to seen, uh, ground check.
Hear what this player.
Ground.
Now let's fix the collider.
Should be like that.
Yeah.
And for the damage trigger, let's decrease it from the Y.
Okay.
This is good.
Uh, ground check.
It's fine.
Everything is fine to me.
Yeah, everything looks fine.
Let's do player detection.
Zero, because we don't need it.
And we'll check.
Distance should be wider.
Something like that.
Now I'm going to go to play mode.
It's supposed to fall and walk left and right.
Oh, wow.
How do you do that?
Why?
Okay, I know, I'm sorry.
Over here.
We need to change to dynamic.
Oh my God!
What is happening to you?
Supposed to fold.
Not like that.
Oh, I know, I'm so sorry.
Like an enemy should be changed to an enemy.
No, this object only.
Okay, let me try again.
Yeah.
All right.
This is good.
He walks.
This is not good, man.
This is not.
Great.
Now let's increase ground check distance to point three and we'll check distance to, uh.
Where is he?
And let's do 1.3.
I'll just take the ground check and move it below like that.
Okay, let's make sure it is working.
We just need to be sure.
I'm going to give it gravity scale of two so it falls faster.
And let's go and see this.
Boom.
Okay.
This is good.
I like it.
Now let's go back to the script and let's adjust it a little bit.
So we're going to need a header.
Reddish details.
And as of now I want to make a public bull is flying just so we know it is working.
Then we need to override.
Override.
Uh, die method.
And over here we're going to do if is flying equals to false, then it's going to do is flying equals
to true.
Else we're just going to kill it as it was before.
All right, then we need to override animator.
Override animator.
And over here we're going to do anim set bool of ease flying.
To ease flying.
Perfect.
Now, uh, from the start.
Let's overwrite.
Start.
We're going to do is Flynn equals to true because it's supposed to start in the air, and I want it
to fly up in a certain way.
I don't want to use vector to move towards.
I want to use rigid bodies velocity.
So we're gonna.
And, uh, serialize field.
Private float.
Why?
Maybe fly force something like that.
And we want to have sterilized field private float, min fly distance.
And this reddish will fly above the ground with a certain like with a certain distance.
And if distance is higher than it should be, then it will stop pushing itself up.
Because of that, it's going to look like it's always trying to fly up, but it cannot.
Uh, you'll see it.
It's really nice.
Then over here we want to handle movement only if we are grounded.
So maybe like that.
And I think.
I think we can do this.
If is flying, then.
And they'll line.
Let's do method.
Are we going to adjust it later on?
As of now, this is good.
We just need to make the fly in logic, and I want to have some sort of a check how far from distance
the radius is.
For that we cannot use boolean.
We need to do something else.
We want to make um private raycast hit to the ground below.
Uh, detected.
And we need to override handle collision.
I'm going to do.
Override.
Handle collision inside.
I want to do ground below.
Detected equals to physics 2D.
Recast.
Transform.
Position vector two dot down.
Um.
We need.
I guess we need a maximum float value here, so float.
Load max value.
And what is ground.
Okay, so this will always make a raycast that is checking where is the ground below.
And it's going to use infinite distance.
So it's going to just detect ground anyway.
Then we're going to go back to the start method.
And in the start we want to make minimum fly distance equals to the current distance we have at the
moment of uh like start of the game.
That's why we're doing this.
In the start.
We sort of saving the default value.
Thanks to that, you can just place radish on the level and you will not have to worry about changing
variables.
It's going to save itself on its own.
And you can just place the radish and it's going to fly approximately on that point.
So we're going to do mean fly distance equals to ground below.
Dot distance.
Just like that.
Now let's go to the fly I mean handle flying.
And over here we're going to do something simple.
If ground below dot distance is less than mean fly distance then we're going to do RB velocity equals
to new vector two.
Uh, zero on the X.
Lifeforce on the Y.
Thanks to this now, reddish supposed to push itself up when it goes down just a bit.
And let's go ahead and try this.
Let's go back to unity and we're going to go to the game window.
I think we need to add fly force, but I don't know how much so.
Let me try.
Fly force.
Maybe.
Three.
Okay.
And I'll place it over here.
So this where it's supposed to be?
Let's say we don't have this piece of ground.
I mean, the platform.
General.
Where is the tile 3D tile palette?
Let's say this one is not there and I need to use reddish to get to this point over here.
So it's supposed to be like that, right?
That's the jump.
Let's go and see it now.
Oh, no.
It fell.
Let's make it true by default.
Supposed to be true anyways.
Um, we're not saving minimum flight distance for some reason.
That's the problem.
Let's go and check it.
All right.
Um, maybe it's not updated by the time it's supposed to be updated here, but I guess it is not updated
at the start.
And that's why it makes it zero.
Let's do it like that.
All right.
We sort of just doing recast once at the start.
I'm going to save it and I'm going to try again.
Please work.
Supposed to work.
All right.
Now it does what we need it to do, right?
It stays above the ground.
And also it's trying to fly up once it's falling down.
So it looks like it's really floaty, like it's trying hard I like it I only want to change something
here.
I want to slow down the animation of a fly, maybe to 15 on the sample rate.
So it looks a bit slower and kind of like lazy here.
And maybe let's reduce gravity scale back to one so it's not so heavy.
And for the fly force, let's try to keep it at three or maybe 3.5.
Okay, now I'm going to see this.
Oh, yeah, I like it a little bit more now.
It's kind of like trying to get up and it cannot.
I think it's good enough.
I like it if you want, you can play with variables.
Just if you make it heavier, it's going to pull harder.
If you make life force higher, it's going to fly up more.
That's what it's going to do.
Now let me just try to check the functionality of it.
Like it's kind of like a falling platform, but life.
You.
So it was not supposed to die.
And.
That's what we need to fix.
Let's go back.
Another method if is flying through.
Then is flying false.
This is how it was supposed to be.
Okay.
Now, if I'm not mistaken.
Uh, wait a second.
Yeah.
It's supposed to fall down.
Then it's supposed to walk left and right.
And after that, we only need to add a little bit of a logic.
We want it to fly back to the position it had once.
It's walked for a bit.
Okay.
Yeah, this is good.
Now, if I jump on, the head is gonna die.
And now we need to make it fly up when it goes back.
So let's go to enemy reddish.
Um, I'm going to use some sort of a timer, private float, walk timer, and let's do serialize field.
Private float walk duration.
Okay.
I'm going to make it equals to two by default just so we can see how it works.
Also, now that we know mean fly distance is updated, we can make it as private without showing it.
And.
I guess this boolean can be private as well because now we know it is working.
All right.
Now.
What do we need when we.
Kick it for the first time.
We're going to do walk timer equals to walk duration.
Just like that.
Then we're going to go to the update and we're going to do else let's open curly brackets and move it
here like that.
Maybe we can move.
This is grounded.
Check inside of a method so it does not bother us here.
And what do you think.
So it's a bit cleaner I'm going to do.
If is grounded false then return.
And same on the movement.
If is grounded.
False return.
Now, thanks to this, we can go back to update and just remove this condition over here.
Very cool.
Inside of this, we're going to do, um, maybe actually, we can do just above.
Uh, walk timer minus equals time delta time.
And then if walk timer is below zero, then.
Is flying.
Equals to true, but this will just make it fly up and we don't want it to just fly up.
We want it to fly approximately on the same position it had.
Um, if we want to do that, we want to save the X position.
So let's go.
And.
Maybe do a private float.
X original position.
And at the start we're going to do x original position equals to transform.
Position dot x.
Nice.
Now we want to go.
To this method and we want to make its Flynn true.
Not only if walk timer is below zero, but also if difference between current text position and original
x position is not very big.
We can do that just by simply do end.
Math.
F absolute.
Maybe.
Let's make a variable for this.
Let's do float.
X difference equals to uh math f dot absolute between transform.position.x and x minus x original position.
And then if X difference is less than maybe 0.15 or 0.1 F.
So difference between position that we have right now an original position is less than 0.1 F means
we are approximately at the same place we were, we at the same place where we supposed to be and we
can make is flying true.
That's the thing.
Uh, let's go and try this.
Let's go back to unity.
I'm just going to hit the play button and it's going to fly there.
I like it, and I'm going to just try to jump on the head of the radish.
Hey, boy.
You.
It's going to fly down.
Walk.
And then it flies up back.
All right, this is it.
This is what we need.
It's going to walk a little bit until the duration is over.
And then it's like, hey, I'm flying up.
Nice.
Very nice.
Yeah, maybe I would like it to fall faster.
Other than that, I think it's good.
Oh.
Or no, we not supposed to have it like that.
Let me try to see if I can kill it while it works.
And then I'm going to check that bug.
It's walking and I'm killing it.
Ah, this is weird.
Let's take the damage trigger and let's reduce it on the Y.
Something like that.
Okay.
On the X can be something like this I think should be okay.
Also, I've got an idea.
I want to make it heavier just when we jump on the head.
So I'm going to do, uh, gravity scale.
RB gravity scale equals to maybe three.
And then when we flying back over here.
I'm going to do gravity scale or be gravity scale equals to one.
Alrighty.
Let me try this again.
I did not like that glitch.
Also, I feel like this animation does not have a flash when we kick it.
Enemy.
Uh, where is it?
Reddish.
It has white sprites, but I feel like I didn't see it.
It becomes white.
Why do I feel like we can't?
A little bit of the animation.
Animator.
Enemy hit.
Our transition duration.
Let's make it zero.
Okay.
Supposed to be good.
Now let's go and try.
You falls down.
Walks around.
And Pew!
Pew!
I love it, boy, this is so pretty.
All right.
Um, last thing I would like to do is sort of a Polish thing, but I really want to do it when we jump
on the head of the enemy for the first time.
It does not flash white, and it looks like just nothing happened.
So I wanted to make it white when we're hitting it for the first time while he's flying.
And we don't have animations for that, so we'll have to code it, but it's not that difficult to do.
We're going to do.
Private eye enumerator.
Oh no, wait, it's not going to be that easy to do either.
Uh.
Okay.
This is what we have to do.
Wait.
I don't remember how it works.
I need to open an RPG course.
All right, here it is.
I just need to check.
The flash material.
How does it work over here?
It just texts shader.
Okay.
And it's empty.
Okay.
This is what we need to do.
And let's go back to our project.
We want to go to asset.
Materials.
I'm going to make material, uh, flesh material.
Okay, we're gonna change it to, um.
GUI text shader.
Just like that.
Now if you go to Sprite renderer and place this material.
Now wait a second.
Not sprite renderer.
Yes, sprite renderer.
If you place this material over here, the.
Red is going to become white completely, then you can revert these changes back to default one.
And we can do this in the script.
Let's go back to the enemy radio script.
I'm going to make a variable.
Let's do space.
Serialized field.
Private material.
Flash material.
Then we want to go down.
Sorry, that was too quick.
Flash material.
That is what we need.
Oh, and also, we need private material.
Uh, regional.
Material.
Then we're going to go to start and do, um, original material equals to SR dot material.
All right.
Now we're going to go down and we're going to make a coroutine.
I enumerator.
Lash fix coroutine.
Let's do right.
Then let's do something like, uh, SR material equals to flash material.
Then we're going to do yield return new.
Let's do wait four seconds of maybe 0.1 F and then SR material equals to original material just like
that.
And then when we kick in it.
We're going to do.
Start.
Coroutine of a flash, a fixed coroutine.
All right.
A quick, neat trick on how to flash.
The sprite.
Now we need to go to this field, assign it with a flash material, and we can go to play mode and see
how it works.
And we're going to be done with this video.
You.
Now it becomes white a little bit when you hit it for the first time, same as it flashes white when
you kick it to kill it.
Yes.
Good.
Good job guys.
I'll see you in the next video.
I'll wait.
Let's make it as a prefab.
We're going to go to enemies and make enemy reddish.
Alrighty, I'll see you in the next one.