1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:01,000
Welcome back.

3
00:00:01,000 --> 00:00:04,000
And in this video, we're going to move our player for the first time.

4
00:00:04,000 --> 00:00:07,000
I'm going to talk a bit about coding.

5
00:00:07,000 --> 00:00:09,000
How are we going to use code in how to make script?

6
00:00:09,000 --> 00:00:13,000
And all of that is very easy and common practice.

7
00:00:13,000 --> 00:00:14,000
I'm sure you will understand it.

8
00:00:14,000 --> 00:00:19,000
And if not in this video, then in the next one just be sure to follow me and repeat my actions.

9
00:00:19,000 --> 00:00:23,000
Because when you do it, your brain absorbs the information.

10
00:00:23,000 --> 00:00:28,000
And he trying to understand that he remembers the code, he remember the movement of the fingers and

11
00:00:28,000 --> 00:00:29,000
so on.

12
00:00:29,000 --> 00:00:31,000
Doing that stuff is essential for learning, right?

13
00:00:31,000 --> 00:00:34,000
So there are two ways to add script to the player.

14
00:00:34,000 --> 00:00:37,000
First is just add component new script.

15
00:00:37,000 --> 00:00:40,000
You give it a name and I'll name minus player to that.

16
00:00:40,000 --> 00:00:43,000
It is done well, let it assemble.

17
00:00:43,000 --> 00:00:50,000
Or you could make it an asset folder at first place, so I'll remove it and delete this one.

18
00:00:51,000 --> 00:00:56,000
Once again, red button, create sharp layer.

19
00:00:57,000 --> 00:01:00,000
And then just drag it here and we can open it.

20
00:01:01,000 --> 00:01:04,000
And this is Visual Studio for now.

21
00:01:04,000 --> 00:01:10,000
As I said, just repeat after me and I'll explain something by bit so you can understand it, because

22
00:01:10,000 --> 00:01:15,000
if I'll let you know all info at once, you'll just feel like, Wow, that's too much for me.

23
00:01:15,000 --> 00:01:23,000
Yeah, what are we going to do here is go above the start function and type public float, move speed.

24
00:01:23,000 --> 00:01:24,000
All right.

25
00:01:24,000 --> 00:01:30,000
So what we did here, we created a variable with a type float and we gave it a name move.

26
00:01:30,000 --> 00:01:37,000
Speed and public means it is accessible from any part of the program, from any part of the script,

27
00:01:37,000 --> 00:01:39,000
from any part of the unit.

28
00:01:39,000 --> 00:01:41,000
We can find it from anywhere and use it.

29
00:01:41,000 --> 00:01:42,000
Major difference for now.

30
00:01:42,000 --> 00:01:45,000
That is, we can see it in the inspector.

31
00:01:47,000 --> 00:01:51,000
All right, So now, look, if I save the script and go back to Unity, I can see my move.

32
00:01:51,000 --> 00:01:53,000
Speed over here and I can change it.

33
00:01:53,000 --> 00:01:56,000
And you might notice I have decimals over there.

34
00:01:56,000 --> 00:01:59,000
So it is 7.6 and 3.7 like that.

35
00:01:59,000 --> 00:02:08,000
Now I want to go back and create another one public float jump force just like that.

36
00:02:08,000 --> 00:02:12,000
Now we can see jump force as well and we can change it as well.

37
00:02:12,000 --> 00:02:15,000
But what if we change this float to int?

38
00:02:16,000 --> 00:02:19,000
Let's do it INT and save it.

39
00:02:19,000 --> 00:02:25,000
And immediately you can see we lost the number and now if we change it, it goes as a whole number.

40
00:02:25,000 --> 00:02:27,000
There is no decimals.

41
00:02:27,000 --> 00:02:32,000
That is the difference between float and integer and they use it for different purposes.

42
00:02:32,000 --> 00:02:34,000
Like move speed can be 4.5.

43
00:02:34,000 --> 00:02:34,000
Right?

44
00:02:34,000 --> 00:02:39,000
But if you have, let's say, amount of coins collected, you cannot have 4.5 coins should be either

45
00:02:39,000 --> 00:02:42,000
four or five, something like that.

46
00:02:42,000 --> 00:02:44,000
Now let's go and type here float.

47
00:02:44,000 --> 00:02:45,000
We have these two variables.

48
00:02:45,000 --> 00:02:46,000
We're going to use them.

49
00:02:46,000 --> 00:02:49,000
And I want to make another variable here.

50
00:02:49,000 --> 00:02:51,000
It's going to be public as well.

51
00:02:51,000 --> 00:02:52,000
Let's make it public.

52
00:02:52,000 --> 00:02:54,000
Read it by the two.

53
00:02:54,000 --> 00:02:58,000
And now we create an a variable of type rigid body.

54
00:02:58,000 --> 00:03:04,000
You can think of them as a jars that store, different information, different type of variables, store

55
00:03:04,000 --> 00:03:05,000
different information.

56
00:03:05,000 --> 00:03:08,000
This one stores info about rigid body.

57
00:03:08,000 --> 00:03:09,000
Now let's give it a name.

58
00:03:09,000 --> 00:03:11,000
Let's put a label on it.

59
00:03:11,000 --> 00:03:16,000
RB Now, if we go back to Unity, we can see it's appeared here.

60
00:03:16,000 --> 00:03:18,000
RB And it says none.

61
00:03:18,000 --> 00:03:23,000
So it is empty and we need to assign it, same as we did just now with the numbers.

62
00:03:23,000 --> 00:03:30,000
So to assign it for now, I'll take my rigid body from the player and just drag it like that.

63
00:03:30,000 --> 00:03:31,000
And this move speed.

64
00:03:31,000 --> 00:03:35,000
I'm going to set to one and jump first to one for the time being.

65
00:03:35,000 --> 00:03:41,000
Now we have the player, we have access to Region body, as you understand now, are being the code.

66
00:03:41,000 --> 00:03:43,000
It's the name of the variable we created.

67
00:03:43,000 --> 00:03:45,000
And these are be the very same.

68
00:03:45,000 --> 00:03:51,000
This are B and these are B is assigned to this rigid body that we have on the player that we control.

69
00:03:51,000 --> 00:03:56,000
And now we can control this rigid body to move the player.

70
00:03:56,000 --> 00:03:57,000
And let's do that.

71
00:03:57,000 --> 00:03:59,000
Just repeat after me in the update.

72
00:03:59,000 --> 00:04:00,000
We type.

73
00:04:00,000 --> 00:04:05,000
RB That velocity equals two new vector two and vector two.

74
00:04:05,000 --> 00:04:07,000
You know, what is x and Y, right?

75
00:04:07,000 --> 00:04:08,000
Pretty simple.

76
00:04:08,000 --> 00:04:15,000
Now we want to move object on the x, We want to make player run to one of the sides.

77
00:04:15,000 --> 00:04:18,000
If you put positive value here, going to run to the right.

78
00:04:18,000 --> 00:04:21,000
If you put negative value, you're going to run to the left.

79
00:04:21,000 --> 00:04:22,000
So let's try that.

80
00:04:22,000 --> 00:04:23,000
Let's just type here.

81
00:04:23,000 --> 00:04:25,000
Speed, move, speed.

82
00:04:25,000 --> 00:04:27,000
Sorry, move speed.

83
00:04:27,000 --> 00:04:28,000
Right.

84
00:04:28,000 --> 00:04:34,000
And for the Y and actually all the info you can see here what it needs vector to construct a new vector

85
00:04:34,000 --> 00:04:37,000
with a given x y component.

86
00:04:37,000 --> 00:04:38,000
Right.

87
00:04:38,000 --> 00:04:44,000
For the Y, we're going to type rb dot velocity, dot y y is that we don't change y of the rigid body,

88
00:04:44,000 --> 00:04:49,000
but if we put zero, it means we set value to zero.

89
00:04:49,000 --> 00:04:50,000
And we don't need to do that.

90
00:04:50,000 --> 00:04:55,000
We need to keep it on velocity on the Y, So we just type RB velocity dot y.

91
00:04:55,000 --> 00:04:56,000
All right, enough talking.

92
00:04:56,000 --> 00:05:00,000
Let's go back to the unity and try this.

93
00:05:00,000 --> 00:05:04,000
I'm going to place my player somewhere at the beginning like that.

94
00:05:05,000 --> 00:05:06,000
I'm going to take my platform.

95
00:05:07,000 --> 00:05:09,000
I'm making bigger like that.

96
00:05:09,000 --> 00:05:15,000
And just make sure you have over here selected 16 to 9 aspect instead of three aspect.

97
00:05:15,000 --> 00:05:15,000
Right.

98
00:05:16,000 --> 00:05:16,000
Cool.

99
00:05:16,000 --> 00:05:19,000
Now hit play and watch this.

100
00:05:19,000 --> 00:05:22,000
He moves slowly, but he does.

101
00:05:22,000 --> 00:05:25,000
If I increase the speed, you're going to move faster.

102
00:05:25,000 --> 00:05:27,000
And if I make it negative.

103
00:05:27,000 --> 00:05:28,000
What's he doing?

104
00:05:28,000 --> 00:05:29,000
He's moving back.

105
00:05:30,000 --> 00:05:34,000
Because we change in his velocity and at the same time we change his position.

106
00:05:34,000 --> 00:05:38,000
You can see in four about velocity of the rigid body over here.

107
00:05:39,000 --> 00:05:40,000
Infer velocity.

108
00:05:43,000 --> 00:05:45,000
You can see it's getting changed.

109
00:05:46,000 --> 00:05:48,000
Oh, here, right now.

110
00:05:48,000 --> 00:05:52,000
You've seen he falls, he's rotating on the Z.

111
00:05:52,000 --> 00:05:54,000
So I'm offering you a small challenge.

112
00:05:54,000 --> 00:06:00,000
In this video, you need to do it right now and just make him not fall on the side like he did.

113
00:06:00,000 --> 00:06:04,000
Make him stand straight, even if he's moving past the video.

114
00:06:04,000 --> 00:06:05,000
Do that.

115
00:06:05,000 --> 00:06:08,000
Come back if you did or if you didn't, it's fine.

116
00:06:08,000 --> 00:06:11,000
And I'll help you to fix that one, too.

117
00:06:12,000 --> 00:06:17,000
So we go to constraints of the rigid body and click Freeze rotation Z.

118
00:06:17,000 --> 00:06:22,000
Now he won't fall and we can increase speed by a bit like three and see how it works.

119
00:06:23,000 --> 00:06:23,000
Doing.

120
00:06:24,000 --> 00:06:28,000
He's running Yeah basically and let's runner is done.

121
00:06:28,000 --> 00:06:29,000
He's running endlessly.

122
00:06:29,000 --> 00:06:30,000
Cool.

123
00:06:30,000 --> 00:06:32,000
Let's go to the next video.

