1
00:00:03,020 --> 00:00:03,700
Welcome back.

2
00:00:03,710 --> 00:00:08,090
As we finished in the last lecture, you can see that currently, Barry, when we click on play just

3
00:00:08,090 --> 00:00:08,720
kind of stops there.

4
00:00:08,720 --> 00:00:12,590
He's not like the ball that was able to roll down this hill using physics.

5
00:00:12,620 --> 00:00:14,750
He's just kind of stuck there and that's fine.

6
00:00:14,750 --> 00:00:19,820
We could solve this by going down the path of adding physics, like adding force that pushes the player

7
00:00:19,820 --> 00:00:23,150
along, that pushes the player a different amount up hills and downhills.

8
00:00:23,450 --> 00:00:24,890
We can play around with gravity.

9
00:00:24,890 --> 00:00:26,870
There's play around the friction on the snowboard.

10
00:00:26,870 --> 00:00:32,240
There's a lot we can do there, or I can show you a really cool feature in Unity and we'll use that

11
00:00:32,240 --> 00:00:34,340
cool feature to make our snowboarder move.

12
00:00:34,340 --> 00:00:39,260
And that cool feature is using an effector and the sort of effector we're going to use is the surface

13
00:00:39,260 --> 00:00:40,220
effect, the 2D.

14
00:00:40,220 --> 00:00:44,960
If you jump over to the Unity documentation, I've given you a link against this lecture for that.

15
00:00:44,960 --> 00:00:50,420
In the resources section you can see that the surface effector to DH applies tangent forces along the

16
00:00:50,420 --> 00:00:51,710
surface of colliders.

17
00:00:51,710 --> 00:00:52,610
What does that mean?

18
00:00:52,610 --> 00:00:58,430
Well, this is analogous to a conveyer belt, so we're trying to make a conveyor belt by adding some

19
00:00:58,430 --> 00:01:01,940
sort of force that we apply along our collider.

20
00:01:01,940 --> 00:01:06,350
So we've got our collider that's going along the edge of our of our world here.

21
00:01:06,350 --> 00:01:11,540
We want to apply a conveyor belt effect to something that pushes anything, that collides with it in

22
00:01:11,540 --> 00:01:12,830
a particular direction.

23
00:01:12,830 --> 00:01:14,750
So it's going to conveyor belt it along.

24
00:01:14,750 --> 00:01:16,550
There's other types of effectors.

25
00:01:16,550 --> 00:01:18,380
Let me just jump back to effect as to do that.

26
00:01:18,380 --> 00:01:25,490
You can play around with their surface effector point effector platform effector buoyancy and area effector.

27
00:01:25,490 --> 00:01:27,440
So there's a few of these that you can play around with.

28
00:01:27,440 --> 00:01:32,570
But for now we're just focusing on this conveyor belt or service effector to DX and it's going to be

29
00:01:32,570 --> 00:01:34,370
easy peasy to implement this.

30
00:01:34,370 --> 00:01:40,460
So what we need to do is click on our level, sprite shape, jump down, find our add component search

31
00:01:40,460 --> 00:01:41,630
for effector.

32
00:01:41,630 --> 00:01:46,490
We're looking for the surface effect, the 2D click, there we go, scroll down.

33
00:01:46,490 --> 00:01:50,840
We can have a look at the details on that and let's click on play and see if anything happens at this

34
00:01:50,840 --> 00:01:51,410
point.

35
00:01:51,770 --> 00:01:52,920
Okay, nothing's happening.

36
00:01:52,920 --> 00:01:55,640
Of course, that means we need to do a little bit of sleuthing in here.

37
00:01:55,640 --> 00:02:00,680
And if you have a look at our Edge collider, you can see there's a setting in here which says Used

38
00:02:00,680 --> 00:02:01,760
by effectors.

39
00:02:01,760 --> 00:02:06,500
In other words, it's saying if you drop an effector on here, it's not necessarily going to know which

40
00:02:06,500 --> 00:02:10,669
edge collider you want to be using because you might have a few edge colliders, but if we say used

41
00:02:10,669 --> 00:02:14,540
by effector now the effector will know, aha, this is the edge.

42
00:02:14,540 --> 00:02:18,230
Collider When something touches this, I'm wanting to push along that edge.

43
00:02:18,230 --> 00:02:20,990
Collider So now when we click on play, we'll see what happens.

44
00:02:21,790 --> 00:02:22,560
Okay.

45
00:02:22,570 --> 00:02:23,170
He's moving.

46
00:02:23,170 --> 00:02:24,040
Wasn't moving before.

47
00:02:24,070 --> 00:02:26,320
Moving very, very slowly.

48
00:02:26,320 --> 00:02:28,180
So let's have a look at our settings in here.

49
00:02:28,180 --> 00:02:31,930
We've got our four speed, we've got our speed variation, we've got our force scale.

50
00:02:31,930 --> 00:02:35,410
Let's try adding 20 into speed and see what happens in here.

51
00:02:35,410 --> 00:02:41,440
So when we click on play now with 20 and our speed for service effector, you see problem Barry's getting

52
00:02:41,440 --> 00:02:42,280
pushed along.

53
00:02:42,280 --> 00:02:47,920
However, he's getting stuck at this point here and that's something that we had our initial success.

54
00:02:47,920 --> 00:02:50,280
Let me just move him up the hill a little bit here.

55
00:02:50,440 --> 00:02:54,790
Make sure you clicked on the parent whenever you do any of these things, because if you click on just

56
00:02:54,790 --> 00:02:58,780
the top, then woop you just move the top, but not the entire game object.

57
00:02:58,780 --> 00:03:00,460
Not Barry in his entirety.

58
00:03:00,460 --> 00:03:04,660
So popping up here, I'm going to click back on my level shape and I'm going to move this down the speed.

59
00:03:04,660 --> 00:03:09,370
I'm going to change that back down to ten just so he's not moving quite so rapidly and flying off the

60
00:03:09,370 --> 00:03:09,670
thingy.

61
00:03:09,670 --> 00:03:12,910
So you can see here he's touching got speed, speed, speed, speed, speed.

62
00:03:12,910 --> 00:03:17,800
You can see the camera is flowing over here, doesn't really rotate very well goes up there up does

63
00:03:17,800 --> 00:03:23,260
a little bit of a jump all good making progress bump and then it gets stuck and falls through the world.

64
00:03:23,260 --> 00:03:27,790
Now the effect is working, but we've got an issue with our collision that's easily solved.

65
00:03:27,790 --> 00:03:31,210
If we click on Barry, we find Barry's rigid body.

66
00:03:31,210 --> 00:03:33,730
You can see collision detection is discrete.

67
00:03:33,730 --> 00:03:36,250
We want that collision detection to be continuous.

68
00:03:36,250 --> 00:03:40,810
So that's going to require more processing power because Barry's the star of the show, we don't mind.

69
00:03:40,810 --> 00:03:43,630
It's going to do a more continuous collision detection.

70
00:03:43,660 --> 00:03:47,950
So if I'm right with this, he will fly down the hill, do his kind of weirdness, but he's not going

71
00:03:47,950 --> 00:03:50,560
to get stuck because we're doing a much better collision detection.

72
00:03:50,560 --> 00:03:55,870
And on this hill, our effector or our conveyor belt is still going to keep pushing him along as we're

73
00:03:55,870 --> 00:03:56,770
expecting it to do.

74
00:03:56,770 --> 00:03:58,150
So that's mission accomplished.

75
00:03:58,150 --> 00:04:03,340
The effector is that easy to move things along if we want to twiddle with it a little bit, you can

76
00:04:03,340 --> 00:04:07,390
see while we're clicked on our level, sprite shapes don't play mode.

77
00:04:07,390 --> 00:04:12,640
If we get there and change the speed to say, I don't know, minus ten, then it's going to make Barry

78
00:04:12,640 --> 00:04:15,370
go backwards because it's pushing in the other direction.

79
00:04:15,370 --> 00:04:16,899
The conveyor belt is going backwards.

80
00:04:16,899 --> 00:04:19,779
We put it back up this way, but do it to a smaller amount.

81
00:04:19,779 --> 00:04:20,829
Then he's moving along.

82
00:04:20,829 --> 00:04:27,460
If you increase the force scale, that's a way of saying don't respond to any of these gravity things

83
00:04:27,460 --> 00:04:28,240
like up the hill.

84
00:04:28,240 --> 00:04:31,900
It's going to go up the hill exactly the same no matter how steep the hill is.

85
00:04:31,900 --> 00:04:37,720
But if I push this all the way down to say 0.001 on the force scale, he's kind of stuck on the hill,

86
00:04:37,740 --> 00:04:39,730
doesn't have enough force to push him up.

87
00:04:39,820 --> 00:04:41,560
And if I increase that, then it does.

88
00:04:41,560 --> 00:04:43,000
If I put it down to zero, not enough.

89
00:04:43,000 --> 00:04:44,860
So a little bit more force, a little bit less.

90
00:04:44,860 --> 00:04:46,150
So you can see there's a relationship.

91
00:04:46,150 --> 00:04:52,120
Speed is how fast he's going to move or how fast the conveyor belt is moving and the force is how much

92
00:04:52,120 --> 00:04:57,940
we're applying that force to counteract any gravity that we might have with our game object.

93
00:04:57,940 --> 00:04:59,320
Where's that gravity coming from?

94
00:04:59,320 --> 00:05:00,550
Well, it's currently on Barry.

95
00:05:00,550 --> 00:05:04,870
If you click on Barry, you can see that he has a gravity scale of one, which is fine.

96
00:05:04,870 --> 00:05:07,690
We can play around with that at some point, but it's cool for now.

97
00:05:07,690 --> 00:05:11,950
So little sprite shape, I'm going to put this back to actually if we get out of play mode because I

98
00:05:11,950 --> 00:05:15,730
was in play mode while I was doing that, it'll reset our values back to what they were when we first

99
00:05:15,730 --> 00:05:17,290
clicked on play mode.

100
00:05:17,290 --> 00:05:18,130
So there we go.

101
00:05:18,130 --> 00:05:21,070
I love Effectors and I love this surface effector.

102
00:05:21,070 --> 00:05:22,090
It's so powerful.

103
00:05:22,090 --> 00:05:27,820
Just by dropping that in instantly, we've got this character moving along, looking like he's a snowboarder.

104
00:05:27,820 --> 00:05:33,580
And one cool thing, if you haven't noticed it already, if you were to increase speed up and decrease

105
00:05:33,580 --> 00:05:36,940
speed, notice how it only affects him when he's in the air.

106
00:05:36,940 --> 00:05:41,020
So if I go woop really fast and then put it all the way down really low, is he going to land on the

107
00:05:41,020 --> 00:05:42,870
world loop?

108
00:05:43,150 --> 00:05:44,590
And he's going backwards now?

109
00:05:44,590 --> 00:05:49,450
So I put it all the way to backwards, but it's only if you're touching the effector that that has an

110
00:05:49,450 --> 00:05:50,680
impact when you're in the air.

111
00:05:50,680 --> 00:05:51,310
It doesn't.

112
00:05:51,310 --> 00:05:54,760
Also it's good to know is that we can modify this value here in our code.

113
00:05:54,760 --> 00:05:59,230
So if the player pushes a key on the keyboard, we can have them speed up if we wanted to, to give

114
00:05:59,230 --> 00:06:00,070
them a boost.

115
00:06:00,070 --> 00:06:00,940
So that's really cool.

116
00:06:00,940 --> 00:06:05,910
Whenever you see these values on the components, just have a think about the fact that, you know,

117
00:06:05,980 --> 00:06:10,090
we can modify these in our code to do cool things such as with the speed.

118
00:06:10,090 --> 00:06:10,720
So there we go.

119
00:06:10,720 --> 00:06:14,830
There's an introduction to effectors, specifically the service effector.

120
00:06:14,830 --> 00:06:18,370
Now we have our snowboard out moving along our world.

121
00:06:18,370 --> 00:06:19,660
I'll see you in the next lecture.

