In this lecture, we're adding to the play of death by changing the state and animation and giving some
sort of visual response.
When you bump into an enemy, I'm going to just fling the play out up in the air a little bit.
Let's start off by changing the animation state for the player when it touches the enemy and we call
our die method.
If you know how to do this, go ahead and dive in.
Maybe do it at the same time.
With me once again, see if we've got a bit of a race going on here.
I'm going to look at my animator.
I'm going to make sure I'm clicked on the player.
So I'm in my animations folder clicking on the player animator controller.
You can see we've got our animation states in here idling, climbing, running.
I'm going to add a new parameter.
So I've got is running, is climbing.
I'll click on my little plus button here and it'll be a trigger this time.
I don't need it to be a ball where we say You're doing that or not doing in that.
This is a one way trip.
We're just going to trigger the death state.
So this trigger will be dying.
And you see there's a little button there that you can click on and off once again, as we've done before.
So I've got this dying and we need animation to create our state here.
So I'm going to look for let's see in sprites, let's find the player.
Where's the player are you player.
There we go.
Open that up and I will find just one of these.
I think I'm not going to try to loop through an animation, but you totally could have the character
animating.
I just want to have one lying on his back with his legs sprawled in the air.
I think that's what's going on there.
It's a little bit difficult to see, isn't it?
If we make it a bit smaller.
Okay, we'll give that one a shot.
That will be number 11.
I'll be using my animation, so I'm going to grab number 11 and just right click on it.
Create animation if I can find where it is.
I always spend a whole bunch of time up and down and up and down.
Here we go.
Animation kind of about two thirds of the way down.
Animation, we'll call this Def Animation and I'll drag that into my animations folder.
Do I stick with my convention?
Then we've got running.
Climbing idle should kind of be idling, shouldn't it?
We get the picture, death or dying.
I'm going to drag that into my animation.
I've got this death state in here.
Now, where do we want this to come from?
Well, we could make a transition from climbing to death, from idling to death, from running to death.
But there's a way that we can do this by grabbing out any state, which is that little blue state icon
there.
And we can put this anywhere we want, put it just down there so we can see it nice and easily.
So create a transition by right clicking on any state.
Make transition to add a line, click it onto death.
Like I said before, this is a one way street, so we don't need to have it come back again.
That will say from any state in our game, go into the death state.
What do we want to do?
Click on the transition line here and just have a look at the settings.
I'm going to put the transition duration to zero fixed duration.
I think that's going to be fine.
Everything else I think is okay, the death.
We don't need to be looping the animation because there's only one frame, so it's just going to stick
on that one frame.
That should be okay.
We need to say how we're getting into this state.
So I'm just going to drag my finger down there a little bit and you can see our conditions is empty
at the moment.
Click the plus button and we'll change that to be dying.
It's a trigger, so there's nothing else to put in there, just dying as a condition when that's triggered,
then we move into this state.
That's good so far.
Next up, what we need to do is look in our code, jump all the way down, down, down, down to our
die within here.
We need to do something after we've said that is alive is no longer true.
It's false.
We need to do something to our animator.
Can you ever think of what that is?
What do we need to do within our animator at this instance?
Well, that was my dramatic pause for you to have a go at it if you did.
Awesome.
We're going to start with my animator, because that's what we've called our reference.
The animator.
Dot set trigger.
This is how we can change the trigger.
It's not set ball as we did just up above there.
It's now set.
Trigger, what is the trigger?
Well, I've learned my lesson of pasting this in recently.
It is the trigger is called.
I'm going to double click on that dying copy back into here string reference in our parentheses.
We don't like string references, but we deal with them because they're useful sometimes and our semicolon
and our red squiggly has gone away.
Great.
So now we're going to change the animation to dying when that's the case.
So I'll save here.
This will be the first part of what I want to do, just to make sure that we're going to fall over legs
up in the air.
It all looks pretty good.
Click on play, bump into our enemy at some point.
He is soon due to do it and it was space primary the enemy boink and we're upside down and being kind
of dragged along.
I think he's upside down legs in the air.
It looks a little bit odd, but anyway, that's good.
But it was a little bit not very dramatic, was it?
So what I'm going to do for me, I'm going to throw the player up into the air.
So when we bump into the enemy, I'm just going to go up like that and kind of give the player a kick
up in the air.
Now you can do a bunch of different things.
You can change the color, you can change the screen, you can make the screen go to black.
You could do some screen, shake whatever you want.
Now, I'm going to give this to you as a challenge, which is to do something nifty for the death state.
When the player collides with the enemy, do something interesting, such as the things I mentioned.
Fling the player across the map, which is what I'll be doing.
Change the player color or add some screen shake or some other wacky thing that you could do and share
in the discussions what you've come up with, particularly if you do something a little bit crazy and
interesting, I'd love to see it.
So pause the video and take on that challenge now.
And we're back and racing.
I'm going to jump into my script.
I'm going to after I change the animation state, I'm going to get the rigid body and do something with
it.
So my rigid body.
Do we have one of those.
My rigid body, yes, we do dot velocity.
I think it's velocity and we will add a death kick now I can say and hit new vector to etc. but I'm
going to parameter ize this.
I'm going to make it as a variable so that we can shoot it in our inspector and I'll name this variable
def kick I think, and then semicolon scroll all the way up to the top.
Let's see in here it's going to be another serialised field, serialize field, and it will be of type
vector to that vector to and we'll call it def kick as we've got down below.
Now did I spell it with a capital K and uppercase K.
I did not a lowercase.
So these two words.
Yes they are two words.
So I'll make that an uppercase K.
It's going to be consistent here and that will be seeing as it's a new vector two we need to say new
vector to to cast it as a vector two and in parentheses.
What do we want to have?
I'm going to have this a ten f comma, ten F save back over into unity.
Click on play, run, run, run, run, hoop.
Oh, does a little jump in there?
It's kind of cute.
And then he goes flying off his slides along the ground.
You must have zero friction on his collider.
That's kind of weird and interesting.
At the same time.
We could go and address that.
We could tell him to stop moving, but I kind of like it.
We'll see if we can fling him a little bit further, though.
So we'll click on the player.
We'll have a look around for where we've got these values in here.
Where is the player movement?
Death Kick will make this 20 and 20 just so it's a good old reaction.
Not a little bit of a oops.
I stubbed my toe, but holy guacamole.
What was that?
So we'll run, run, run.
Boog has flung up in the air and he's getting dragged along by the enemy.
But that's good for now.
We're saying to the player, you have perished, you can't control the player anymore.
So I'm happy with that process.
So good stuff.
I look forward to seeing the death kick that you've come up with or the death result.
And I'll see you in the next lecture.