1 00:00:04,220 --> 00:00:05,180 ‫Welcome back. 2 00:00:05,210 --> 00:00:08,420 ‫In this video, we are going to take care of our records. 3 00:00:08,420 --> 00:00:12,200 ‫So far, we can't move them and that's what we want to change in this video. 4 00:00:12,230 --> 00:00:17,300 ‫Therefore, we need two scripts, one for record player one and one for record player two. 5 00:00:17,300 --> 00:00:26,330 ‫So let's add a component, a new script, and I'm going to call that record player one. 6 00:00:27,380 --> 00:00:32,540 ‫And the record player to script is something that you will do that you should try yourself. 7 00:00:32,540 --> 00:00:35,630 ‫So let's go ahead with the record player one script first. 8 00:00:35,900 --> 00:00:38,450 ‫What we will need in here is very simple. 9 00:00:38,450 --> 00:00:39,860 ‫It's really just one thing. 10 00:00:39,860 --> 00:00:46,100 ‫We will need the fixed update method, which will constantly check if the user presses a button and 11 00:00:46,100 --> 00:00:52,430 ‫if he presses a specific button, then the record should move and the record should move with a specific 12 00:00:52,430 --> 00:00:52,760 ‫speed. 13 00:00:52,760 --> 00:00:58,730 ‫So that means we need a public float movement speed value. 14 00:00:58,760 --> 00:01:04,010 ‫A good value here would be 200, for example, so that the player can move the record with the speed 15 00:01:04,010 --> 00:01:04,940 ‫of 200. 16 00:01:05,900 --> 00:01:09,890 ‫Other than that, let's create a fixed update method here. 17 00:01:10,640 --> 00:01:16,070 ‫It's an internal method from unity and it will be called a fixed amount of times per second. 18 00:01:16,070 --> 00:01:18,320 ‫So for example, 60 times per second. 19 00:01:19,220 --> 00:01:25,580 ‫Now what we need to do is check if the user pressed a button and save that within a float value. 20 00:01:25,580 --> 00:01:35,480 ‫So I'm going to save that into V, which is our vertical value and it should get the input of our user. 21 00:01:35,660 --> 00:01:43,490 ‫And the input I want to have is the access row, which that does is returns the value of the virtual 22 00:01:43,490 --> 00:01:47,810 ‫access identified by access name with no smoothing filtering applied. 23 00:01:47,810 --> 00:01:49,700 ‫So it doesn't change. 24 00:01:49,730 --> 00:01:56,390 ‫It doesn't matter if you press hard or soft, it will simply take the raw value and it will simply, 25 00:01:56,390 --> 00:02:00,560 ‫if the user pressed, let's say w it will go up. 26 00:02:00,560 --> 00:02:01,910 ‫So the record will go up. 27 00:02:01,910 --> 00:02:04,670 ‫So that means the value here will be one. 28 00:02:04,700 --> 00:02:09,380 ‫If it is, if you press this as the value will be minus one. 29 00:02:09,380 --> 00:02:11,330 ‫So the record will go down. 30 00:02:11,600 --> 00:02:13,850 ‫And now of course we need the access name. 31 00:02:13,850 --> 00:02:15,140 ‫And how do we get that? 32 00:02:15,140 --> 00:02:20,570 ‫Well, I'm just going to enter vertical here, which are the vertical axis. 33 00:02:20,900 --> 00:02:24,830 ‫But how we do that, how we get that is within unity. 34 00:02:25,250 --> 00:02:32,390 ‫We can go ahead and go to edit project settings input. 35 00:02:33,080 --> 00:02:38,540 ‫And there as you can see here, the input manager opens on the right hand side within the expect inspector 36 00:02:38,540 --> 00:02:46,790 ‫and you can see that there are 618 axes and one of them is vertical and that vertical axis is what we 37 00:02:46,790 --> 00:02:47,480 ‫want to use. 38 00:02:47,480 --> 00:02:53,270 ‫So it says here down up as w this is the vertical axis. 39 00:02:53,390 --> 00:02:59,390 ‫But what I want to change is I want to have a vertical axis for player one and another vertical axis 40 00:02:59,390 --> 00:03:00,440 ‫for the player too. 41 00:03:00,440 --> 00:03:06,950 ‫So, so the arrow keys are for player two for example, and SE and W are for player one so that we can 42 00:03:06,950 --> 00:03:08,810 ‫play on the same keyboard. 43 00:03:08,990 --> 00:03:11,990 ‫And for that we need to have another. 44 00:03:13,040 --> 00:03:13,760 ‫Input. 45 00:03:14,300 --> 00:03:16,580 ‫So you have vertical here as well. 46 00:03:16,580 --> 00:03:17,850 ‫That's not what we want. 47 00:03:17,870 --> 00:03:22,150 ‫I want to change the size, so I'm going to change that to 19. 48 00:03:22,160 --> 00:03:31,130 ‫So that means I get another one here at the bottom and I'm going to call that vertical two and down 49 00:03:31,130 --> 00:03:34,040 ‫and up will get deleted from it. 50 00:03:34,040 --> 00:03:39,980 ‫So I'm going to say the negative button will be down and the positive button will be up. 51 00:03:42,550 --> 00:03:43,390 ‫And here. 52 00:03:46,140 --> 00:03:47,400 ‫The all positive button. 53 00:03:47,400 --> 00:03:48,510 ‫We don't need that. 54 00:03:50,070 --> 00:03:53,730 ‫And the other values I copy from our vertical. 55 00:03:53,970 --> 00:03:58,870 ‫I activate snap here at the bottom sensitivity three should be fine. 56 00:03:58,890 --> 00:04:01,530 ‫Gravity three should be fine as well. 57 00:04:01,770 --> 00:04:06,210 ‫So now we have an axis called vertical and another axis called vertical two. 58 00:04:06,480 --> 00:04:08,280 ‫And the vertical one should be four. 59 00:04:08,280 --> 00:04:10,570 ‫Play one, and the other one should be for player two. 60 00:04:10,590 --> 00:04:17,070 ‫So that means I need to change this one to be S and W and the alt buttons will not be used. 61 00:04:17,070 --> 00:04:18,930 ‫So we don't have alternative buttons. 62 00:04:18,930 --> 00:04:21,150 ‫It's just S and W for player one. 63 00:04:21,450 --> 00:04:21,930 ‫All right. 64 00:04:21,930 --> 00:04:28,230 ‫So we have the axis one that we created ourself, which is called vertical two and one that was there 65 00:04:28,230 --> 00:04:29,940 ‫already, which is called vertical. 66 00:04:29,940 --> 00:04:31,770 ‫And we changed that a little bit. 67 00:04:31,920 --> 00:04:37,830 ‫Right now that we have that, you see, we take the vertical axis here, which is the input that we 68 00:04:37,830 --> 00:04:39,540 ‫just changed. 69 00:04:39,780 --> 00:04:44,580 ‫Now that we have that, we can go ahead and change the speed of our racket. 70 00:04:44,580 --> 00:04:54,990 ‫So we get the component which is our rigid body to DX of our racket and we change the velocity to being 71 00:04:55,410 --> 00:05:04,170 ‫a new vector two, which is zero and as the y value V multiplied with movement speed. 72 00:05:05,100 --> 00:05:08,640 ‫So that's the whole script for our record player one. 73 00:05:09,570 --> 00:05:15,500 ‫Now let's have a look at Unity again and let's see if we can make our record move now. 74 00:05:15,510 --> 00:05:19,110 ‫So record player one has the script, record player one which is good. 75 00:05:19,200 --> 00:05:25,380 ‫Now what it has is a box to DX Collider, so that's perfect as well because that's what we want to change. 76 00:05:25,380 --> 00:05:27,360 ‫But it doesn't have a rigid body yet. 77 00:05:27,360 --> 00:05:34,290 ‫So let's add the component physics to DX, rigid body to DX, and we don't need gravity here. 78 00:05:34,320 --> 00:05:35,420 ‫That's important. 79 00:05:35,430 --> 00:05:38,150 ‫Now we of course need to change the movement speed. 80 00:05:38,160 --> 00:05:44,550 ‫So here our record player, one script has a movement speed let's try 200 and now let's test the game. 81 00:05:45,090 --> 00:05:46,740 ‫Let's see if our racket can move. 82 00:05:46,740 --> 00:05:50,760 ‫And as you can see, I can move my record on the left hand side. 83 00:05:50,970 --> 00:05:54,480 ‫So now please go ahead and try the same thing with the record too. 84 00:05:54,480 --> 00:06:01,200 ‫So do all of the procedure that I've just shown you and reproduce that with our record too. 85 00:06:01,860 --> 00:06:07,650 ‫And as you can see, my record is a little bit influenced by by the ball's physics. 86 00:06:07,650 --> 00:06:09,660 ‫That's not really something that we want. 87 00:06:12,120 --> 00:06:16,920 ‫So we will need to add constraints to it because currently it's rotating. 88 00:06:19,180 --> 00:06:21,940 ‫And I don't want it to retain a rotate. 89 00:06:21,940 --> 00:06:30,160 ‫So I'm going to freeze the Z position and the ex position of my racquet. 90 00:06:30,160 --> 00:06:35,950 ‫So now it shouldn't get dragged to or pull pushed to one or the other side. 91 00:06:37,360 --> 00:06:38,980 ‫And as you can see, it's stiff now. 92 00:06:39,070 --> 00:06:42,460 ‫All right, please go ahead and try to do the same thing with the record player, too. 93 00:06:42,460 --> 00:06:48,400 ‫So pause the video, try to reproduce what you've just seen and check out with it works. 94 00:06:50,020 --> 00:06:50,410 ‫All right. 95 00:06:50,410 --> 00:06:51,310 ‫I hope you tried it. 96 00:06:51,310 --> 00:06:57,550 ‫So we need to create a new script, which I'm going to call record player two. 97 00:06:59,080 --> 00:07:08,590 ‫I'm going to open it up in Unity and I'm going to copy all the code from here and paste it in here. 98 00:07:08,980 --> 00:07:14,920 ‫So what I'm the only thing I'm going to change is I'm going to change the axis, which is now vertical 99 00:07:14,920 --> 00:07:15,490 ‫two. 100 00:07:16,300 --> 00:07:21,460 ‫So that will take the up and down arrow in order to move the record. 101 00:07:21,790 --> 00:07:27,730 ‫The rest can stay the same because it's really just the Y value and that should be the same functionality 102 00:07:27,730 --> 00:07:28,930 ‫for both records. 103 00:07:29,380 --> 00:07:33,490 ‫Now that we have that, we need to add a rigid body to. 104 00:07:33,490 --> 00:07:35,890 ‫DX, I hope you managed to do that. 105 00:07:35,890 --> 00:07:39,190 ‫So let's add the rigid body to the two R record. 106 00:07:39,280 --> 00:07:41,770 ‫Let's get rid of the gravity scale. 107 00:07:41,770 --> 00:07:47,020 ‫So enter zero and let's add the constraints for the x and z value. 108 00:07:47,020 --> 00:07:50,830 ‫So only y can be changed by our player. 109 00:07:52,330 --> 00:07:58,270 ‫Now we of course need to change the movement speed and if we wanted to be unfair, we could give 300, 110 00:07:58,270 --> 00:08:03,400 ‫for example, to our player two and only 200 as the record movement speed for a player one. 111 00:08:03,400 --> 00:08:09,430 ‫And that would make it highly unfair because as you can see, I'm going to use the buttons at the same 112 00:08:09,430 --> 00:08:10,120 ‫speed. 113 00:08:10,210 --> 00:08:17,050 ‫And once again, as you can see, the left is not going with the same speed as the right record. 114 00:08:17,050 --> 00:08:22,540 ‫So that would be a way to cheat the game a little bit or to make it harder for player one or two. 115 00:08:23,020 --> 00:08:23,410 ‫All right. 116 00:08:23,410 --> 00:08:29,260 ‫So if you would like to play the game, let's say with your three year old brother who can barely hold 117 00:08:29,260 --> 00:08:35,260 ‫the controller, that would be an option to make it fair so that your record is slower than his and 118 00:08:35,260 --> 00:08:38,470 ‫he is more likely to hit the ball that way. 119 00:08:38,950 --> 00:08:39,400 ‫All right. 120 00:08:39,400 --> 00:08:40,720 ‫I hope you manage to do that. 121 00:08:40,720 --> 00:08:46,860 ‫It wasn't really too much functionality to add what was really important to add the script copied it. 122 00:08:47,140 --> 00:08:50,440 ‫The code change, of course, the input. 123 00:08:50,860 --> 00:08:54,340 ‫So within the project settings you had to change the input. 124 00:08:54,340 --> 00:08:56,320 ‫Of course you had to create vertical too. 125 00:08:56,590 --> 00:09:01,990 ‫And then of course add the movement speed, add the rigid body to DX and so forth. 126 00:09:02,110 --> 00:09:02,740 ‫Great. 127 00:09:02,740 --> 00:09:04,540 ‫So now let's clean up a little bit. 128 00:09:04,540 --> 00:09:10,750 ‫Let's drag those two scripts into your scripts folder and let's save our scene. 129 00:09:10,930 --> 00:09:19,090 ‫And in the next video, we are going to have a look at the physics of our records, because so far the 130 00:09:19,090 --> 00:09:20,500 ‫ball only goes left and right. 131 00:09:20,500 --> 00:09:26,230 ‫It doesn't really care about whether it hits the record at the top or at the bottom part of it. 132 00:09:26,230 --> 00:09:31,750 ‫Because what I want to have is if it hits it at the top, then the ball should have a different Y value. 133 00:09:31,960 --> 00:09:34,390 ‫So it should go towards the top. 134 00:09:34,390 --> 00:09:37,330 ‫If it hits it at the bottom, it should go towards the bottom. 135 00:09:37,480 --> 00:09:40,960 ‫That's really important for Pong, otherwise it would be a super boring game. 136 00:09:41,170 --> 00:09:41,590 ‫Great. 137 00:09:41,590 --> 00:09:43,150 ‫So see you in the next video.