1 00:00:04,150 --> 00:00:05,110 ‫Welcome back. 2 00:00:05,140 --> 00:00:10,000 ‫In this video, we are going to create the resetting functionality. 3 00:00:10,000 --> 00:00:16,990 ‫So that means whenever somebody scored the ball gets reset to a specific position based off of whose 4 00:00:17,020 --> 00:00:17,740 ‫turn it is. 5 00:00:17,740 --> 00:00:21,460 ‫So if it's player plays one turn, it will be on the left hand side. 6 00:00:21,460 --> 00:00:24,010 ‫If its play is to turn, it will be on the right hand side. 7 00:00:24,010 --> 00:00:26,380 ‫So that's what we want to do. 8 00:00:26,380 --> 00:00:33,280 ‫And of course we also want to have the game over screen, so we want to go to game over at one point. 9 00:00:33,430 --> 00:00:33,850 ‫All right. 10 00:00:33,850 --> 00:00:37,780 ‫So in order to get all of that done, let's go to our scripts. 11 00:00:37,780 --> 00:00:41,620 ‫And the ones that are relevant is the ball movement. 12 00:00:41,920 --> 00:00:45,820 ‫Then our collision controller and our score controller. 13 00:00:45,820 --> 00:00:47,080 ‫Those are the three scripts. 14 00:00:47,110 --> 00:00:50,500 ‫All right, so let's go into a ball movement script in here. 15 00:00:50,500 --> 00:00:54,430 ‫We need to go ahead and reposition the ball. 16 00:00:54,490 --> 00:00:59,470 ‫We need at least a method in order to position the ball correctly or reposition the ball. 17 00:00:59,470 --> 00:01:02,440 ‫So I'm going to create a new method. 18 00:01:02,440 --> 00:01:11,050 ‫I'm going to call it position ball and it needs a Boolean in order to know where the starting position 19 00:01:11,050 --> 00:01:11,470 ‫should be. 20 00:01:11,470 --> 00:01:14,440 ‫Is it player one or is it player two who is starting? 21 00:01:15,130 --> 00:01:19,480 ‫So I'm going to call it is starting player one. 22 00:01:22,270 --> 00:01:27,310 ‫So whenever we want to start the game, we first of all want to reduce the velocity of the ball. 23 00:01:27,310 --> 00:01:30,130 ‫So it should go back to the velocity of zero. 24 00:01:30,130 --> 00:01:32,200 ‫So there should be no velocity at all. 25 00:01:32,230 --> 00:01:42,760 ‫So we say this dot get component and we want to have the rigid two body, rigid body to DX. 26 00:01:42,790 --> 00:01:50,170 ‫And of that we changed the velocity to a new vector to which is zero comma zero. 27 00:01:50,380 --> 00:01:54,880 ‫A velocity of zero towards both directions is no velocity at all. 28 00:01:56,950 --> 00:02:06,340 ‫Now if it's player once turn, so if starting player or is starting player one is true, we want the 29 00:02:06,340 --> 00:02:07,900 ‫ball to be at a position. 30 00:02:07,960 --> 00:02:18,100 ‫So game object dot transform dot local position which is a vector three variable is a new vector three 31 00:02:18,970 --> 00:02:22,270 ‫at -100 zero zero. 32 00:02:25,440 --> 00:02:29,940 ‫So that means the ball will be just left off the center. 33 00:02:31,420 --> 00:02:36,940 ‫And if it's not player one who is turning this, then we want it to be on the right hand side. 34 00:02:36,940 --> 00:02:43,030 ‫So we copy that code and say positive value 100 for the X value. 35 00:02:43,630 --> 00:02:48,490 ‫So that method will simply position the ball correctly whenever we restart the game, for example, 36 00:02:48,490 --> 00:02:50,770 ‫or whenever somebody scored. 37 00:02:51,040 --> 00:02:55,690 ‫And that's also something that we should call whenever we start our ball. 38 00:02:55,690 --> 00:03:05,380 ‫So that means we go here, dot this position ball and we hand over the starting player variable. 39 00:03:05,800 --> 00:03:06,250 ‫All right. 40 00:03:06,250 --> 00:03:12,070 ‫So now that we have that, we have to check out our our collision controller, because in here, if 41 00:03:12,070 --> 00:03:22,150 ‫the ball hits the left wall, we want to start a CO routine, start co routine, this dot ball movement 42 00:03:22,150 --> 00:03:24,340 ‫dot start ball. 43 00:03:24,490 --> 00:03:26,740 ‫And here we need to hand over a boolean. 44 00:03:26,740 --> 00:03:29,350 ‫Or we can at least and I'll just say true. 45 00:03:30,190 --> 00:03:36,700 ‫So that means the ball should start on the left hand side and we do the same thing if it hits the right 46 00:03:36,700 --> 00:03:37,210 ‫ball. 47 00:03:37,890 --> 00:03:44,310 ‫So if it is the right ball start KO routine this ball movement start ball and in this case a false. 48 00:03:44,520 --> 00:03:53,850 ‫So that means that our starting player is false and if our starting player one is false, that means 49 00:03:53,850 --> 00:03:55,080 ‫player two starts. 50 00:03:57,080 --> 00:03:57,800 ‫All right. 51 00:03:59,060 --> 00:04:01,310 ‫So now that we have that, let's check it out. 52 00:04:01,310 --> 00:04:04,100 ‫Let's see if all is working fine. 53 00:04:07,660 --> 00:04:10,120 ‫So let's lose the first one. 54 00:04:10,120 --> 00:04:11,770 ‫You see, the score is increased. 55 00:04:11,770 --> 00:04:14,980 ‫The ball is at the left hand side again. 56 00:04:16,150 --> 00:04:17,680 ‫Now let's check it out. 57 00:04:17,680 --> 00:04:19,390 ‫Let's go towards the other side. 58 00:04:19,570 --> 00:04:25,090 ‫And there's one point and at the same time, it's player to turn. 59 00:04:25,660 --> 00:04:33,880 ‫All right, so whenever somebody scores, the other players turn starts, great. 60 00:04:33,880 --> 00:04:35,170 ‫So we have that. 61 00:04:35,170 --> 00:04:37,540 ‫We have the resetting of our ball. 62 00:04:37,540 --> 00:04:43,300 ‫Now what we need to do is, of course, we need sound and we need a game over scene. 63 00:04:43,300 --> 00:04:46,660 ‫And I would say it's best if we do that in the next video. 64 00:04:46,870 --> 00:04:48,400 ‫So just a quick recap. 65 00:04:48,400 --> 00:04:49,420 ‫What did we do? 66 00:04:49,450 --> 00:04:56,470 ‫We create a new method within ball movement which positions our ball and the based on whose player's 67 00:04:56,470 --> 00:04:57,340 ‫turn it is. 68 00:04:57,400 --> 00:05:00,040 ‫The ball is on the left hand side or on the right hand side. 69 00:05:00,040 --> 00:05:07,540 ‫At the same time, we stop this the speed or reduce the velocity of the ball to zero, comma, zero, 70 00:05:07,540 --> 00:05:10,420 ‫and whenever we collide with the ball. 71 00:05:10,420 --> 00:05:12,220 ‫So whenever the ball collides with the ball. 72 00:05:12,220 --> 00:05:16,870 ‫So we reposition the ball here with our start co routine. 73 00:05:17,530 --> 00:05:17,860 ‫Great. 74 00:05:17,860 --> 00:05:23,020 ‫So let's see you in the next video where we will use our score controller in order to go to the game 75 00:05:23,020 --> 00:05:23,740 ‫over screen. 76 00:05:23,740 --> 00:05:26,770 ‫And also, of course, we will add the game over screen. 77 00:05:26,770 --> 00:05:27,760 ‫So see you there.