1
00:00:03,080 --> 00:00:07,340
In this lecture, we're adding to the play of death by changing the state and animation and giving some

2
00:00:07,340 --> 00:00:08,630
sort of visual response.

3
00:00:08,630 --> 00:00:12,230
When you bump into an enemy, I'm going to just fling the play out up in the air a little bit.

4
00:00:12,230 --> 00:00:16,550
Let's start off by changing the animation state for the player when it touches the enemy and we call

5
00:00:16,550 --> 00:00:17,360
our die method.

6
00:00:17,360 --> 00:00:19,310
If you know how to do this, go ahead and dive in.

7
00:00:19,340 --> 00:00:20,390
Maybe do it at the same time.

8
00:00:20,390 --> 00:00:22,970
With me once again, see if we've got a bit of a race going on here.

9
00:00:23,000 --> 00:00:24,290
I'm going to look at my animator.

10
00:00:24,290 --> 00:00:26,150
I'm going to make sure I'm clicked on the player.

11
00:00:26,150 --> 00:00:29,900
So I'm in my animations folder clicking on the player animator controller.

12
00:00:29,900 --> 00:00:33,620
You can see we've got our animation states in here idling, climbing, running.

13
00:00:33,620 --> 00:00:35,240
I'm going to add a new parameter.

14
00:00:35,240 --> 00:00:36,830
So I've got is running, is climbing.

15
00:00:36,830 --> 00:00:39,710
I'll click on my little plus button here and it'll be a trigger this time.

16
00:00:39,710 --> 00:00:42,710
I don't need it to be a ball where we say You're doing that or not doing in that.

17
00:00:42,710 --> 00:00:43,940
This is a one way trip.

18
00:00:43,940 --> 00:00:45,650
We're just going to trigger the death state.

19
00:00:45,650 --> 00:00:48,050
So this trigger will be dying.

20
00:00:48,050 --> 00:00:51,590
And you see there's a little button there that you can click on and off once again, as we've done before.

21
00:00:51,590 --> 00:00:55,010
So I've got this dying and we need animation to create our state here.

22
00:00:55,010 --> 00:01:00,110
So I'm going to look for let's see in sprites, let's find the player.

23
00:01:00,110 --> 00:01:01,280
Where's the player are you player.

24
00:01:01,280 --> 00:01:01,880
There we go.

25
00:01:01,910 --> 00:01:04,730
Open that up and I will find just one of these.

26
00:01:04,730 --> 00:01:08,690
I think I'm not going to try to loop through an animation, but you totally could have the character

27
00:01:08,690 --> 00:01:09,110
animating.

28
00:01:09,110 --> 00:01:12,650
I just want to have one lying on his back with his legs sprawled in the air.

29
00:01:12,650 --> 00:01:14,060
I think that's what's going on there.

30
00:01:14,060 --> 00:01:15,530
It's a little bit difficult to see, isn't it?

31
00:01:15,530 --> 00:01:16,970
If we make it a bit smaller.

32
00:01:16,970 --> 00:01:18,470
Okay, we'll give that one a shot.

33
00:01:18,470 --> 00:01:19,940
That will be number 11.

34
00:01:19,940 --> 00:01:24,170
I'll be using my animation, so I'm going to grab number 11 and just right click on it.

35
00:01:24,170 --> 00:01:27,350
Create animation if I can find where it is.

36
00:01:27,350 --> 00:01:29,840
I always spend a whole bunch of time up and down and up and down.

37
00:01:29,840 --> 00:01:30,320
Here we go.

38
00:01:30,320 --> 00:01:32,660
Animation kind of about two thirds of the way down.

39
00:01:32,660 --> 00:01:38,280
Animation, we'll call this Def Animation and I'll drag that into my animations folder.

40
00:01:38,280 --> 00:01:39,500
Do I stick with my convention?

41
00:01:39,500 --> 00:01:40,310
Then we've got running.

42
00:01:40,310 --> 00:01:43,250
Climbing idle should kind of be idling, shouldn't it?

43
00:01:43,670 --> 00:01:45,920
We get the picture, death or dying.

44
00:01:46,580 --> 00:01:49,610
I'm going to drag that into my animation.

45
00:01:49,610 --> 00:01:51,680
I've got this death state in here.

46
00:01:51,710 --> 00:01:53,120
Now, where do we want this to come from?

47
00:01:53,120 --> 00:01:57,110
Well, we could make a transition from climbing to death, from idling to death, from running to death.

48
00:01:57,110 --> 00:02:02,510
But there's a way that we can do this by grabbing out any state, which is that little blue state icon

49
00:02:02,510 --> 00:02:02,660
there.

50
00:02:02,660 --> 00:02:06,230
And we can put this anywhere we want, put it just down there so we can see it nice and easily.

51
00:02:06,230 --> 00:02:09,229
So create a transition by right clicking on any state.

52
00:02:09,229 --> 00:02:12,200
Make transition to add a line, click it onto death.

53
00:02:12,200 --> 00:02:15,890
Like I said before, this is a one way street, so we don't need to have it come back again.

54
00:02:16,010 --> 00:02:19,700
That will say from any state in our game, go into the death state.

55
00:02:19,700 --> 00:02:20,480
What do we want to do?

56
00:02:20,480 --> 00:02:23,870
Click on the transition line here and just have a look at the settings.

57
00:02:23,870 --> 00:02:27,380
I'm going to put the transition duration to zero fixed duration.

58
00:02:27,380 --> 00:02:29,060
I think that's going to be fine.

59
00:02:29,060 --> 00:02:31,490
Everything else I think is okay, the death.

60
00:02:31,490 --> 00:02:35,330
We don't need to be looping the animation because there's only one frame, so it's just going to stick

61
00:02:35,330 --> 00:02:36,170
on that one frame.

62
00:02:36,170 --> 00:02:37,430
That should be okay.

63
00:02:37,430 --> 00:02:39,860
We need to say how we're getting into this state.

64
00:02:39,860 --> 00:02:44,090
So I'm just going to drag my finger down there a little bit and you can see our conditions is empty

65
00:02:44,090 --> 00:02:44,630
at the moment.

66
00:02:44,630 --> 00:02:47,330
Click the plus button and we'll change that to be dying.

67
00:02:47,330 --> 00:02:51,440
It's a trigger, so there's nothing else to put in there, just dying as a condition when that's triggered,

68
00:02:51,440 --> 00:02:52,730
then we move into this state.

69
00:02:52,730 --> 00:02:53,690
That's good so far.

70
00:02:53,690 --> 00:02:58,580
Next up, what we need to do is look in our code, jump all the way down, down, down, down to our

71
00:02:58,580 --> 00:02:59,750
die within here.

72
00:02:59,750 --> 00:03:03,500
We need to do something after we've said that is alive is no longer true.

73
00:03:03,500 --> 00:03:04,040
It's false.

74
00:03:04,040 --> 00:03:05,720
We need to do something to our animator.

75
00:03:05,720 --> 00:03:07,010
Can you ever think of what that is?

76
00:03:07,010 --> 00:03:10,580
What do we need to do within our animator at this instance?

77
00:03:12,330 --> 00:03:15,480
Well, that was my dramatic pause for you to have a go at it if you did.

78
00:03:15,510 --> 00:03:16,120
Awesome.

79
00:03:16,140 --> 00:03:19,300
We're going to start with my animator, because that's what we've called our reference.

80
00:03:19,320 --> 00:03:20,010
The animator.

81
00:03:20,040 --> 00:03:22,130
Dot set trigger.

82
00:03:22,140 --> 00:03:24,370
This is how we can change the trigger.

83
00:03:24,390 --> 00:03:26,750
It's not set ball as we did just up above there.

84
00:03:26,760 --> 00:03:27,240
It's now set.

85
00:03:27,270 --> 00:03:28,540
Trigger, what is the trigger?

86
00:03:28,560 --> 00:03:31,070
Well, I've learned my lesson of pasting this in recently.

87
00:03:31,080 --> 00:03:33,060
It is the trigger is called.

88
00:03:33,060 --> 00:03:38,790
I'm going to double click on that dying copy back into here string reference in our parentheses.

89
00:03:38,790 --> 00:03:43,980
We don't like string references, but we deal with them because they're useful sometimes and our semicolon

90
00:03:43,980 --> 00:03:45,240
and our red squiggly has gone away.

91
00:03:45,240 --> 00:03:45,570
Great.

92
00:03:45,570 --> 00:03:48,150
So now we're going to change the animation to dying when that's the case.

93
00:03:48,150 --> 00:03:48,870
So I'll save here.

94
00:03:48,870 --> 00:03:53,490
This will be the first part of what I want to do, just to make sure that we're going to fall over legs

95
00:03:53,490 --> 00:03:54,150
up in the air.

96
00:03:54,150 --> 00:03:55,320
It all looks pretty good.

97
00:03:55,320 --> 00:03:58,860
Click on play, bump into our enemy at some point.

98
00:03:58,860 --> 00:04:05,490
He is soon due to do it and it was space primary the enemy boink and we're upside down and being kind

99
00:04:05,490 --> 00:04:06,030
of dragged along.

100
00:04:06,030 --> 00:04:07,500
I think he's upside down legs in the air.

101
00:04:07,500 --> 00:04:09,030
It looks a little bit odd, but anyway, that's good.

102
00:04:09,030 --> 00:04:11,280
But it was a little bit not very dramatic, was it?

103
00:04:11,280 --> 00:04:14,790
So what I'm going to do for me, I'm going to throw the player up into the air.

104
00:04:14,790 --> 00:04:19,589
So when we bump into the enemy, I'm just going to go up like that and kind of give the player a kick

105
00:04:19,589 --> 00:04:20,300
up in the air.

106
00:04:20,310 --> 00:04:22,260
Now you can do a bunch of different things.

107
00:04:22,260 --> 00:04:26,670
You can change the color, you can change the screen, you can make the screen go to black.

108
00:04:26,670 --> 00:04:28,800
You could do some screen, shake whatever you want.

109
00:04:28,800 --> 00:04:32,610
Now, I'm going to give this to you as a challenge, which is to do something nifty for the death state.

110
00:04:32,610 --> 00:04:37,020
When the player collides with the enemy, do something interesting, such as the things I mentioned.

111
00:04:37,650 --> 00:04:39,780
Fling the player across the map, which is what I'll be doing.

112
00:04:39,780 --> 00:04:45,510
Change the player color or add some screen shake or some other wacky thing that you could do and share

113
00:04:45,510 --> 00:04:48,840
in the discussions what you've come up with, particularly if you do something a little bit crazy and

114
00:04:48,840 --> 00:04:50,670
interesting, I'd love to see it.

115
00:04:50,670 --> 00:04:53,760
So pause the video and take on that challenge now.

116
00:04:57,350 --> 00:04:59,600
And we're back and racing.

117
00:04:59,600 --> 00:05:02,450
I'm going to jump into my script.

118
00:05:02,450 --> 00:05:07,730
I'm going to after I change the animation state, I'm going to get the rigid body and do something with

119
00:05:07,730 --> 00:05:07,910
it.

120
00:05:07,910 --> 00:05:10,310
So my rigid body.

121
00:05:10,310 --> 00:05:11,000
Do we have one of those.

122
00:05:11,000 --> 00:05:14,660
My rigid body, yes, we do dot velocity.

123
00:05:14,660 --> 00:05:20,810
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

124
00:05:20,810 --> 00:05:23,270
going to parameter ize this.

125
00:05:23,270 --> 00:05:28,430
I'm going to make it as a variable so that we can shoot it in our inspector and I'll name this variable

126
00:05:28,430 --> 00:05:33,290
def kick I think, and then semicolon scroll all the way up to the top.

127
00:05:33,650 --> 00:05:39,170
Let's see in here it's going to be another serialised field, serialize field, and it will be of type

128
00:05:39,170 --> 00:05:45,080
vector to that vector to and we'll call it def kick as we've got down below.

129
00:05:45,110 --> 00:05:48,860
Now did I spell it with a capital K and uppercase K.

130
00:05:48,980 --> 00:05:50,540
I did not a lowercase.

131
00:05:50,540 --> 00:05:51,890
So these two words.

132
00:05:51,890 --> 00:05:52,860
Yes they are two words.

133
00:05:52,860 --> 00:05:55,180
So I'll make that an uppercase K.

134
00:05:55,460 --> 00:06:00,950
It's going to be consistent here and that will be seeing as it's a new vector two we need to say new

135
00:06:00,950 --> 00:06:04,760
vector to to cast it as a vector two and in parentheses.

136
00:06:04,760 --> 00:06:05,810
What do we want to have?

137
00:06:05,810 --> 00:06:12,830
I'm going to have this a ten f comma, ten F save back over into unity.

138
00:06:12,830 --> 00:06:15,290
Click on play, run, run, run, run, hoop.

139
00:06:15,290 --> 00:06:16,510
Oh, does a little jump in there?

140
00:06:16,520 --> 00:06:16,970
It's kind of cute.

141
00:06:16,970 --> 00:06:20,810
And then he goes flying off his slides along the ground.

142
00:06:20,840 --> 00:06:23,150
You must have zero friction on his collider.

143
00:06:23,150 --> 00:06:25,100
That's kind of weird and interesting.

144
00:06:25,100 --> 00:06:25,820
At the same time.

145
00:06:25,820 --> 00:06:27,020
We could go and address that.

146
00:06:27,020 --> 00:06:29,330
We could tell him to stop moving, but I kind of like it.

147
00:06:29,330 --> 00:06:31,160
We'll see if we can fling him a little bit further, though.

148
00:06:31,160 --> 00:06:32,330
So we'll click on the player.

149
00:06:32,360 --> 00:06:34,850
We'll have a look around for where we've got these values in here.

150
00:06:34,850 --> 00:06:35,930
Where is the player movement?

151
00:06:35,930 --> 00:06:39,950
Death Kick will make this 20 and 20 just so it's a good old reaction.

152
00:06:39,950 --> 00:06:40,970
Not a little bit of a oops.

153
00:06:40,970 --> 00:06:43,070
I stubbed my toe, but holy guacamole.

154
00:06:43,070 --> 00:06:43,730
What was that?

155
00:06:43,730 --> 00:06:45,260
So we'll run, run, run.

156
00:06:45,440 --> 00:06:49,070
Boog has flung up in the air and he's getting dragged along by the enemy.

157
00:06:49,070 --> 00:06:49,880
But that's good for now.

158
00:06:49,880 --> 00:06:53,750
We're saying to the player, you have perished, you can't control the player anymore.

159
00:06:53,750 --> 00:06:55,040
So I'm happy with that process.

160
00:06:55,040 --> 00:06:55,730
So good stuff.

161
00:06:55,730 --> 00:06:59,060
I look forward to seeing the death kick that you've come up with or the death result.

162
00:06:59,060 --> 00:07:00,350
And I'll see you in the next lecture.

