Hello guys.
Welcome to the video.
In this one we're going to make a trunk enemy.
It's basically a mix of a mushroom enemy and plant enemy.
You're going to walk left and right.
And when he sees you he's going to shoot.
Simple as that.
Let's go and take the mushroom.
I'm going to duplicate him.
Let's do prefab unpack completely.
And let's call him Enemy Trunk.
Then we need to take all of the sprites, make pixel per unit 16, and also we want to take idle sprite
and drag it to the.
Sprite renderer over here.
Okay, cool.
Now let's reset the collider and let's remove this script.
Gonna reset the collider.
I think we can adjust it to something like.
This.
And for damage trigger.
I guess we can just keep it as it is.
This is good enough.
Yeah, I like it.
Okay, now let's make animator.
We're going to go to animations enemies.
Let's make trunk folder.
Then inside we're going to need animator controller, enemy trunk AC.
We're going to put it on the animator over here.
Then in the animations we need to make new clip.
Let's do.
Enemy trunk idol.
We're going to go to graphics over here.
Enemies.
Trunk.
And we're going to take all of these sprites over here.
Sample array 20.
Then we need enemy.
Trunk move.
We're going to take these animations over here.
Drag them.
Sample rate 20.
Okay.
Now let's, uh.
What is that?
That is part of the animation or that is the enemy.
What is that?
That is the enemy going to place him here.
I don't know how that happened.
Anyway, so we have Trunk Idol.
And try and move.
Okay.
Now we're going to add enemy trunk hit.
There is the hit animation.
Sample rate 20.
And we're going to need attack animation.
So I'm going to make a new clip.
Enemy trunk attack.
Let's take these.
Drag them here.
Sample rate 20.
Now we're going to go to assets animations enemies.
Trunk.
And we're going to just take these actually attack and hit and uncheck loop time.
Now let's set up animator.
We're going to open the animator.
And it's not visible for me because I need to restart unity.
That's what I'm going to do.
Let me save the project.
All right.
Here is the animations.
Let's make a float variable for the blend tree x velocity.
And we need trigger for the hit.
And then we need trigger for the attack.
Okay.
We're going to make blend tree for the idle and move.
So I'm going to do idle move.
Let's open the blend tree.
Here we're going to need three motion fields.
Minus one.
Zero.
One.
Or we can take, uh, clips from here.
So let's place move.
Idle move.
Very well.
So this is going to work.
Let's go and make this by default.
Now we can remove these two from here and then we can take I'm sorry.
Trunk attack with transfer to the attack from idle move if trigger of the attack was called with the
exit diamond check and transition duration zero and we're going to transfer to idle move with the exit
time one.
And transition duration zero.
Very good.
Now this enemy trunk heat can be transferred to from any state with an unchecked can transit to self
transition duration.
Zero condition should be heat triggered.
Very nice.
Animator is ready.
It is on the enemy.
Now let's go and make a script.
Assets.
Scripts.
I'm going to make a new one.
Enemy trunk.
Let me open this.
I'm going to do close all but this for now.
And we're going to just.
Inherit from the enemy.
Very well.
Now let's think how it's going to work.
Enemy trunk is basically like a mushroom.
He walks left and right.
Only the difference is that when he detects the player, he's going to stop the movement and he's going
to attack the player.
That's what we're going to do.
So I guess we can go to enemy mushroom and take the code from here.
Let's take it.
Go back to enemy trunk, place it here.
And we can basically utilize most of the script from here.
And let's just go to enemy plant.
We're going to take the header.
I'm going to just copy the header on the enemy trunk.
I'm going to paste the header and change it to trunk details.
Tracking details.
Okay.
Then let's go to enemy plant again.
And just.
Copy these three methods.
Yet these two methods.
I'm going to copy them.
Go to enemy mushroom.
Sorry.
Enemy trunk.
Paste them in here.
And then we need to go to enemy plant again.
Take this code, copy it, go to enemy rank.
Paste it in here.
As I said, it's just a mix of two enemies basically, so we don't really need to change much here.
Only thing I want to do is to trigger idle time every time trunk is attacking, so enemy will stand
at one place and not move for a while.
Okay.
That's what I want to do.
So maybe.
Yeah, we use idle timer here.
So I think we can go to attack method.
And over here I'm going to do.
Idle timer is equal to.
And here we need ideal duration, but maybe a bit longer than idle duration.
Let's try with ideal duration only for now.
So what's the logic here is when he sees the player he's going to attack.
And at that time we're going to trigger idle timer.
Because of that handle, movement will not work and he'll stand at one place.
Once idle timer is over.
He's going to keep moving until he detects the player again or until he detects the ledge or a wall.
Okay.
Hmm.
Let's go back to unity.
You're going to take enemy trunk.
Let's find attack animation.
You're going to find a place of his attack.
So it's here.
I'm going to add event of.
Oh, sorry.
We need to place the script on enemy trunk.
Okay.
So we're going to add event of method.
Three bullet.
Then on the enemy trunk.
What is ground?
Ground?
What is player?
Player and ground check is long enough, so it's okay.
I'm going to take the ground check itself.
Place it in front of the enemy here.
Then let's assign it over here.
And let's assign gunpoint, which we don't have yet.
So I'm going to make one gunpoint.
Gunpoint should be here.
We can drag it to the gun point over here and we'll check distance.
I cannot see it because of a player detection, so I'm going to make it zero for now.
Now I can see.
We'll check distance.
So I guess we'll check.
Distance eight is fine and then player detection 15 is fine as well.
Now we need a bullet for this enemy before we test everything, because I think it's going to work anyway.
Let's go to asset prefab.
There is an enemy bullet.
I'm going to drag it here.
Change the name to enemy.
Bullet plant.
Let's apply.
We cannot apply.
Override.
Okay.
Uh, how can we solve this?
We're going to just take it away from here.
Do prefab, unpack completely, then drag it here again as a prefab on the enemy plant.
We need to reassign bullet over here.
So this is good.
Now I can take this, uh, bullet change to enemy bullet trunk.
Go to, uh, let's do prefab and completely.
So now this is a new object.
You're going to go to graphics of the enemy trunk.
Take the bullet sprite.
Place it here.
And then we're going to just.
And then we're going to just, uh, go to prefab again, drag it here, and then give this bullet to
the enemy trunk over here.
Okay.
Now it can be deleted from the scene, and I guess it should be fine.
Now.
It has idle time.
It has movement speed.
Everything is ready.
Let's go to play mode.
So he walks.
Here and there.
He flips now he sees me and he attacks.
Very cool, I like it.
Now, if I go away from the.
Like I can see he does a little bit of a step.
That's why I said we need longer idle duration, longer than the, uh, usually we have, I think.
We can go there.
Sorry.
Where is the enemy trunk?
Here.
And we can do idle duration plus attack cooldown.
Yeah, this is a bit better.
And also I've seen, like, feels like bullet is in front of the enemy.
So I'm going to go to the prefab of the bullet enemy trunk sprite renderer.
I'm going to do order in layer minus one.
Also, I want to flip the bullet.
Let me check how it is flying right now.
So when it goes to the left, it's fine.
Um, but if I stand on the right.
Wait for him to go back.
Yeah.
Now it's supposed to be facing another direction, I believe.
So what we can do here is to flip the bullet every time we create it.
Let's go to enemy trunk.
Uh, here is a bullet we have, so maybe we can make a method on the bullet.
Let's do peak definition.
Actually, let's just go to definition.
Hmm?
Come on.
Man.
Enemy.
Bullet.
Go to definition.
Okay.
Over here.
I'm going to do private sprite renderer.
SR.
SR equals to get component of a sprite renderer.
And then I'm going to do public void flip sprite.
And I'm going to do just SR dot flip x equals to not sr flip x okay.
Now we can go back to enemy trunk.
And I think I can do close all but this.
And over here I'm going to check if facing direction is equals to one.
Which means we are facing to the right.
Then new bullet flip sprite.
Just that.
And I guess it's basically ready.
We can go back to unity.
And because we had most of the functionality on other enemies, we just had to flip parameters a little
bit.
Let's go to play mode.
Okay.
He shoots me.
This is nice.
Now I'm going to wait for him to go and flip himself.
And he flips the bullet as well.
Very cool.
And can we kill him?
Let me check.
Boom!
Yay!
Very good.
I love it, man.
So, believe me or not, it's done.
He's ready.
Let's go to prefabs.
Let's make enemy prefab over here.
And I'm going to delete it from the scene.
And we're good to go to the next video.