1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:05,000
So in this video, we're going to make background move together with a player and it's going to feel

3
00:00:05,000 --> 00:00:06,000
like endless background.

4
00:00:06,000 --> 00:00:09,000
Let me explain when character is moving.

5
00:00:09,000 --> 00:00:10,000
You can see that.

6
00:00:10,000 --> 00:00:13,000
You can see that the camera moves with him, the camera, its borders.

7
00:00:13,000 --> 00:00:16,000
And as well, we can see it has the position on the X.

8
00:00:17,000 --> 00:00:18,000
It's moving over here.

9
00:00:18,000 --> 00:00:23,000
So we're going to take our background and I'll just take one layer to explain.

10
00:00:23,000 --> 00:00:28,000
So we have a background and character runs out of a background.

11
00:00:28,000 --> 00:00:30,000
And at this point, you see.

12
00:00:31,000 --> 00:00:36,000
When background is behind the camera, we're going to take it and place it.

13
00:00:39,000 --> 00:00:40,000
Like this.

14
00:00:41,000 --> 00:00:47,000
But because our background going to have duplicates on the left and on the right side, let me demonstrate

15
00:00:47,000 --> 00:00:51,000
that you just watch for now and then we're going to make it together.

16
00:00:51,000 --> 00:00:54,000
So this one will be minus one.

17
00:00:54,000 --> 00:00:55,000
This one one.

18
00:00:55,000 --> 00:00:57,000
We're going to have long background, right?

19
00:00:57,000 --> 00:01:00,000
And we have our main background in the center like this.

20
00:01:00,000 --> 00:01:08,000
Then when character exits the main part of the background till here, we're going to take it and.

21
00:01:10,000 --> 00:01:11,000
Place it.

22
00:01:12,000 --> 00:01:12,000
Like this.

23
00:01:14,000 --> 00:01:16,000
But because it is the same.

24
00:01:16,000 --> 00:01:16,000
Let me see.

25
00:01:16,000 --> 00:01:21,000
71 position 71 and this is 41.

26
00:01:21,000 --> 00:01:21,000
Right.

27
00:01:22,000 --> 00:01:25,000
So what's going to happen real quick?

28
00:01:25,000 --> 00:01:26,000
Just within one frame?

29
00:01:26,000 --> 00:01:33,000
In a millisecond, it's going to be like this was 41 and it will become 71.

30
00:01:33,000 --> 00:01:36,000
You see, you cannot notice the difference.

31
00:01:36,000 --> 00:01:40,000
Well, you can, but basically, we will not be able to notice the difference.

32
00:01:40,000 --> 00:01:42,000
And we just need to do this in the code.

33
00:01:42,000 --> 00:01:45,000
So player runs out of the background like this.

34
00:01:46,000 --> 00:01:53,000
Then we take this background and just change position to what is going to be and it will be unnoticeable

35
00:01:53,000 --> 00:01:54,000
completely.

36
00:01:55,000 --> 00:02:00,000
But we moved background so it's going to feel like an endless I guess it'll be easier to understand

37
00:02:00,000 --> 00:02:01,000
once we make it work.

38
00:02:03,000 --> 00:02:03,000
For now.

39
00:02:03,000 --> 00:02:04,000
Let's just.

40
00:02:05,000 --> 00:02:07,000
Creed C sharp.

41
00:02:09,000 --> 00:02:13,000
Parallax background and go inside.

42
00:02:14,000 --> 00:02:17,000
So as you know, we need a position of the camera.

43
00:02:17,000 --> 00:02:18,000
Let's do this.

44
00:02:18,000 --> 00:02:23,000
We're going to type sorry, private camera, and we're going to name it as Cam.

45
00:02:23,000 --> 00:02:27,000
Then we need serialize field private.

46
00:02:27,000 --> 00:02:28,000
Float.

47
00:02:30,000 --> 00:02:36,000
PA relax multiplayer or parallax effect, let's name it as effect.

48
00:02:36,000 --> 00:02:42,000
Then we need private float lengths of the background and we're going to just name it as lengths.

49
00:02:42,000 --> 00:02:48,000
And we need private float, we need X position of the background.

50
00:02:48,000 --> 00:02:51,000
So we're going to just type it as X position.

51
00:02:51,000 --> 00:02:52,000
All right.

52
00:02:52,000 --> 00:02:55,000
Now let's go to start function over here and make Oh, sorry guys.

53
00:02:55,000 --> 00:02:58,000
This should be game object, not camera.

54
00:02:58,000 --> 00:03:01,000
We're going to use camera, but it's going to be game object.

55
00:03:01,000 --> 00:03:01,000
Yeah.

56
00:03:02,000 --> 00:03:03,000
So let's do this.

57
00:03:03,000 --> 00:03:07,000
Cam equals to game object dot find.

58
00:03:08,000 --> 00:03:10,000
Main camera.

59
00:03:11,000 --> 00:03:12,000
The name is very important.

60
00:03:12,000 --> 00:03:16,000
We can it in the inspector, but I want to show you how to use game object dot find.

61
00:03:16,000 --> 00:03:17,000
Right.

62
00:03:17,000 --> 00:03:19,000
Although please never use a game object.

63
00:03:19,000 --> 00:03:21,000
Don't find in the update.

64
00:03:21,000 --> 00:03:21,000
Never.

65
00:03:21,000 --> 00:03:23,000
It's going to overload your system.

66
00:03:23,000 --> 00:03:30,000
Now links will be equals to get component of sprite renderer.

67
00:03:31,000 --> 00:03:36,000
And then dot bounce, dot size, dot x, this is the length.

68
00:03:36,000 --> 00:03:39,000
So what we do in here, we take in component.

69
00:03:40,000 --> 00:03:48,000
E we take in component of the sprite renderer over here, the one we created first, if you remember,

70
00:03:48,000 --> 00:03:54,000
which I can, how long it is, and then we take value of that and now we need X position, and x position

71
00:03:54,000 --> 00:03:58,000
will be equals to transform that position that x.

72
00:03:58,000 --> 00:04:04,000
Now let's go to update and in the update it might be a bit confusing, but just stay with me in the

73
00:04:04,000 --> 00:04:04,000
update.

74
00:04:04,000 --> 00:04:10,000
First, we need to define distance that we're going to use to move background distance that we're going

75
00:04:10,000 --> 00:04:11,000
to use to move game object.

76
00:04:11,000 --> 00:04:13,000
And it's going to be different for every background.

77
00:04:13,000 --> 00:04:15,000
That's why we have parallax effect.

78
00:04:15,000 --> 00:04:17,000
It's going to work like a multiplier.

79
00:04:17,000 --> 00:04:17,000
So let's do this.

80
00:04:17,000 --> 00:04:26,000
Float distance equals to can de transform dot position dot x multiplied by parallax effect.

81
00:04:26,000 --> 00:04:26,000
That's cool.

82
00:04:26,000 --> 00:04:30,000
Now let's click enter one time and type transform position.

83
00:04:30,000 --> 00:04:35,000
And here we're going to change position of the background with the distance that we just created so

84
00:04:35,000 --> 00:04:43,000
equals to new vector three On an x, we need x position plus distance we calculated and you know, to

85
00:04:43,000 --> 00:04:49,000
make it easier to understand, let's rename it with the control R It's going to be distance to move.

86
00:04:49,000 --> 00:04:55,000
All right then for the Y, we don't need to change it so it can be just transformed position that Y

87
00:04:55,000 --> 00:04:58,000
and we actually don't have to type Z if we're not using it with this code.

88
00:04:58,000 --> 00:05:02,000
We make our background layers move forward.

89
00:05:02,000 --> 00:05:02,000
All right.

90
00:05:02,000 --> 00:05:05,000
Let's go and see that in the unity.

91
00:05:06,000 --> 00:05:08,000
We're going to select all of them.

92
00:05:08,000 --> 00:05:11,000
Drag the script like that and just.

93
00:05:11,000 --> 00:05:13,000
For the first test.

94
00:05:13,000 --> 00:05:14,000
Let's put one for all of them.

95
00:05:15,000 --> 00:05:18,000
And you can see they move in together with the camera.

96
00:05:18,000 --> 00:05:22,000
Now we need to make them move according to how far it should feel.

97
00:05:22,000 --> 00:05:25,000
Let's select the first one and make it move slow.

98
00:05:25,000 --> 00:05:29,000
Let's put point three that select second one, 2.5.

99
00:05:29,000 --> 00:05:31,000
And I'm just throwing values because this is not final.

100
00:05:31,000 --> 00:05:33,000
And I want to show you just what I mean.

101
00:05:33,000 --> 00:05:39,000
Now, look, if I uncheck Pose, you can see objects moving with a different speed and it feels like

102
00:05:39,000 --> 00:05:41,000
something in real life.

103
00:05:41,000 --> 00:05:45,000
Now, let's go and make it jump in front of the character when it goes far.

104
00:05:45,000 --> 00:05:48,000
You remember how I showed you in the beginning of the video?

105
00:05:48,000 --> 00:05:53,000
The background should jump in the center of the screen once it went too far.

106
00:05:53,000 --> 00:05:57,000
So to do that, first, we need to know how far we moved this object.

107
00:05:57,000 --> 00:05:58,000
So let's do this.

108
00:05:58,000 --> 00:06:08,000
Float distance moved equals to cam transform position dot x multiplied by one minus parallax effect.

109
00:06:08,000 --> 00:06:09,000
Now we have this value.

110
00:06:10,000 --> 00:06:16,000
We're going to check if distance moved bigger than x position.

111
00:06:16,000 --> 00:06:20,000
Plus this plus lengths.

112
00:06:20,000 --> 00:06:26,000
Then we're going to do x position equals two x position plus lengths.

113
00:06:26,000 --> 00:06:31,000
So if we moved out of the length of that background, we need to put it back.

114
00:06:31,000 --> 00:06:35,000
Let's go back to Unity and we're going to change the speed again.

115
00:06:35,000 --> 00:06:38,000
So the first one, let's do point three.

116
00:06:39,000 --> 00:06:41,000
Second one, let's do point five.

117
00:06:41,000 --> 00:06:43,000
We might change it later.

118
00:06:43,000 --> 00:06:43,000
Might not.

119
00:06:43,000 --> 00:06:50,000
We need to see it first point seven for the third one and 0.9 for the fourth one.

120
00:06:50,000 --> 00:06:51,000
Like that.

121
00:06:53,000 --> 00:06:55,000
Now let's see if his jump in where we needed to be.

122
00:06:58,000 --> 00:06:59,000
I'm going to run.

123
00:07:00,000 --> 00:07:05,000
And over here at the top and the scene window, we can see it's jumping, right?

124
00:07:07,000 --> 00:07:07,000
All of it.

125
00:07:10,000 --> 00:07:11,000
Yes.

126
00:07:11,000 --> 00:07:12,000
Okay.

127
00:07:12,000 --> 00:07:15,000
Now, what we need to do is to make it feel like an endless.

128
00:07:15,000 --> 00:07:18,000
So what I want to ask you is to select all of these.

129
00:07:18,000 --> 00:07:19,000
Duplicate them twice.

130
00:07:19,000 --> 00:07:23,000
Now, let's select all of the duplicates and remove the script.

131
00:07:23,000 --> 00:07:24,000
Okay.

132
00:07:24,000 --> 00:07:28,000
Now I'm going to select background one.

133
00:07:28,000 --> 00:07:29,000
One.

134
00:07:29,000 --> 00:07:31,000
Make it a child of the first one.

135
00:07:32,000 --> 00:07:35,000
And I'll just move it here so I can see it.

136
00:07:35,000 --> 00:07:41,000
The first one will be minus one on the X is to put additional part from the left and additional part

137
00:07:41,000 --> 00:07:42,000
from the right side.

138
00:07:42,000 --> 00:07:47,000
Look, if I'm selecting the second duplicate and make position one, it's going to be here.

139
00:07:48,000 --> 00:07:51,000
All right, Now let's do for the second one.

140
00:07:51,000 --> 00:07:53,000
Where is one to move it here.

141
00:07:54,000 --> 00:07:55,000
Well, let's arrange all of them.

142
00:07:55,000 --> 00:07:57,000
And then three, three.

143
00:07:59,000 --> 00:08:02,000
And then four and four.

144
00:08:04,000 --> 00:08:06,000
And five and five.

145
00:08:08,000 --> 00:08:10,000
And let's do the five.

146
00:08:11,000 --> 00:08:12,000
Minus one.

147
00:08:13,000 --> 00:08:14,000
One.

148
00:08:15,000 --> 00:08:16,000
Next one.

149
00:08:16,000 --> 00:08:17,000
Where is it?

150
00:08:18,000 --> 00:08:19,000
Minus one.

151
00:08:21,000 --> 00:08:22,000
One.

152
00:08:24,000 --> 00:08:25,000
Third one.

153
00:08:27,000 --> 00:08:30,000
Minus one and one.

154
00:08:31,000 --> 00:08:32,000
And second one.

155
00:08:35,000 --> 00:08:36,000
Minus one.

156
00:08:37,000 --> 00:08:38,000
One.

157
00:08:38,000 --> 00:08:42,000
Now, look, we have a feeling of a long background, right?

158
00:08:42,000 --> 00:08:43,000
Like it's long.

159
00:08:43,000 --> 00:08:49,000
What I want to ask you now is to go to play mode and don't look at the scene window.

160
00:08:49,000 --> 00:08:52,000
Look at the game window and see if you notice anything.

161
00:08:52,000 --> 00:08:53,000
All right.

162
00:08:56,000 --> 00:08:59,000
Okay, I see the triangle, but it's endless.

163
00:08:59,000 --> 00:09:00,000
You see it, right?

164
00:09:00,000 --> 00:09:03,000
We cannot see the jumps of the background.

165
00:09:03,000 --> 00:09:04,000
It feels flawless.

166
00:09:05,000 --> 00:09:07,000
Now let's fix that triangle.

167
00:09:07,000 --> 00:09:08,000
I don't know what's wrong with it.

168
00:09:09,000 --> 00:09:11,000
What is the layer of the triangle I need to know?

169
00:09:13,000 --> 00:09:14,000
This is the one.

170
00:09:15,000 --> 00:09:17,000
Hey, what's up with you, dude?

171
00:09:17,000 --> 00:09:19,000
Why you behave like that?

172
00:09:19,000 --> 00:09:21,000
Oh, because we didn't change background.

173
00:09:22,000 --> 00:09:23,000
And what it should be.

174
00:09:23,000 --> 00:09:25,000
Minus one.

175
00:09:27,000 --> 00:09:28,000
OC.

176
00:09:30,000 --> 00:09:30,000
Not.

177
00:09:31,000 --> 00:09:33,000
Oh, they all the default.

178
00:09:34,000 --> 00:09:34,000
Certainly.

179
00:09:34,000 --> 00:09:35,000
Oh, my God.

180
00:09:35,000 --> 00:09:37,000
I'm so bad.

181
00:09:38,000 --> 00:09:39,000
Okay.

182
00:09:39,000 --> 00:09:41,000
What we can do is to.

183
00:09:41,000 --> 00:09:42,000
I'll try to do that.

184
00:09:42,000 --> 00:09:45,000
Select all of them.

185
00:09:46,000 --> 00:09:47,000
Background.

186
00:09:47,000 --> 00:09:48,000
Now, let's.

187
00:09:48,000 --> 00:09:49,000
Well, this is my bed.

188
00:09:51,000 --> 00:09:52,000
I'm so sorry.

189
00:09:52,000 --> 00:09:56,000
We need to select all of them and make it background.

190
00:09:56,000 --> 00:09:58,000
Then let's go to second one.

191
00:10:01,000 --> 00:10:02,000
I don't know.

192
00:10:02,000 --> 00:10:03,000
How did I miss this?

193
00:10:04,000 --> 00:10:07,000
Open and select all of the pictures.

194
00:10:10,000 --> 00:10:11,000
And set it to background.

195
00:10:13,000 --> 00:10:14,000
Third one.

196
00:10:19,000 --> 00:10:20,000
Background.

197
00:10:27,000 --> 00:10:30,000
Background and last one.

198
00:10:35,000 --> 00:10:36,000
Background.

199
00:10:36,000 --> 00:10:37,000
Okay.

200
00:10:37,000 --> 00:10:44,000
Now, you see, you might need to adjust it a bit according to how yours looks right now, because,

201
00:10:44,000 --> 00:10:46,000
for example, I don't really like mine.

202
00:10:47,000 --> 00:10:51,000
First, what we need to do, I guess, is to let me see if I run.

203
00:10:54,000 --> 00:10:54,000
Yeah.

204
00:10:54,000 --> 00:10:56,000
There is something below.

205
00:10:56,000 --> 00:10:57,000
I can see something below.

206
00:10:57,000 --> 00:11:00,000
So I need to take this first layer.

207
00:11:01,000 --> 00:11:02,000
Um.

208
00:11:04,000 --> 00:11:05,000
Over here.

209
00:11:05,000 --> 00:11:06,000
Find.

210
00:11:08,000 --> 00:11:14,000
The bottom square number 17 and make it all the way down like maybe that.

211
00:11:16,000 --> 00:11:18,000
17 on the way down.

212
00:11:20,000 --> 00:11:20,000
17.

213
00:11:20,000 --> 00:11:21,000
All the way down.

214
00:11:21,000 --> 00:11:22,000
Yeah.

215
00:11:23,000 --> 00:11:26,000
And maybe wider.

216
00:11:31,000 --> 00:11:33,000
Now if I make my plan from Slim.

217
00:11:42,000 --> 00:11:42,000
It's okay.

218
00:11:48,000 --> 00:11:49,000
Okay, That's cool, right?

219
00:11:49,000 --> 00:11:50,000
That's ACTU.

220
00:11:50,000 --> 00:11:52,000
We have something else important.

221
00:11:52,000 --> 00:11:58,000
If you have your background acts like weird or your player, you see it's jittering right now, my player

222
00:11:58,000 --> 00:12:01,000
or now I have my background jittering like that.

223
00:12:01,000 --> 00:12:03,000
So it's about the center machine brain.

224
00:12:03,000 --> 00:12:08,000
You need to select your main camera, find any machine brain over here and change it.

225
00:12:08,000 --> 00:12:11,000
You need to play with it what works for you?

226
00:12:11,000 --> 00:12:12,000
But it's supposed to be smart.

227
00:12:12,000 --> 00:12:15,000
Update and fixed update.

228
00:12:15,000 --> 00:12:16,000
No, wait.

229
00:12:17,000 --> 00:12:18,000
Late update.

230
00:12:18,000 --> 00:12:18,000
Yeah.

231
00:12:18,000 --> 00:12:21,000
So smart update and late update should fix it for me.

232
00:12:21,000 --> 00:12:24,000
It was smart update and a late update over here.

233
00:12:24,000 --> 00:12:29,000
You can see and make sure your player set to interpolate in the region body.

234
00:12:29,000 --> 00:12:31,000
And if you still have some issues like that, no worries.

235
00:12:31,000 --> 00:12:33,000
It's going to be fixed later in the course.

236
00:12:33,000 --> 00:12:34,000
Just leave it for now.

237
00:12:34,000 --> 00:12:35,000
All right.

238
00:12:35,000 --> 00:12:36,000
Let's move on.

