1 00:00:04,170 --> 00:00:05,250 ‫Welcome back. 2 00:00:05,280 --> 00:00:11,040 ‫In this video, I would like to add an eye to my player to record. 3 00:00:11,040 --> 00:00:12,660 ‫And this is a little challenge. 4 00:00:12,660 --> 00:00:14,040 ‫You can try it yourself. 5 00:00:14,040 --> 00:00:16,200 ‫And I would highly recommend to do that. 6 00:00:16,410 --> 00:00:20,310 ‫So this way you will learn how to move something yourself by code. 7 00:00:20,340 --> 00:00:25,920 ‫You have done that already, but now you will do that in a little different way and you will follow 8 00:00:25,920 --> 00:00:27,770 ‫along with the ball, for example. 9 00:00:27,780 --> 00:00:33,660 ‫So post the video, try it by yourself, and once you're done you can check out how I've done it. 10 00:00:33,840 --> 00:00:39,210 ‫And if you're not interested in the exercise at all, you can also simply watch how I do it. 11 00:00:39,600 --> 00:00:41,160 ‫All right, so let's get started. 12 00:00:41,610 --> 00:00:47,940 ‫We need to add another script to our record player, too. 13 00:00:47,940 --> 00:00:50,370 ‫So I'm going to create a new script. 14 00:00:51,740 --> 00:00:57,010 ‫Which I call record player to a. 15 00:01:00,530 --> 00:01:05,410 ‫And now the question is, what does this record player to I need? 16 00:01:05,530 --> 00:01:10,450 ‫Well, it needs a speed and then it needs to follow along our ball. 17 00:01:10,510 --> 00:01:16,450 ‫So the means we need a a movement speed which is a float movement speed. 18 00:01:17,290 --> 00:01:19,280 ‫And we need the ball to follow. 19 00:01:19,300 --> 00:01:22,510 ‫So public game object ball. 20 00:01:23,710 --> 00:01:30,040 ‫And now within our fixed update method, we can check where is the ball and where are we? 21 00:01:30,070 --> 00:01:40,630 ‫So if math f which is a collection of common math functions dot EPS. 22 00:01:40,630 --> 00:01:46,660 ‫So if the absolute value which means it doesn't matter if it's a negative or a positive value in the 23 00:01:46,660 --> 00:01:49,750 ‫end, well the result will be a positive value. 24 00:01:49,750 --> 00:01:52,120 ‫So it returns a static float. 25 00:01:52,120 --> 00:01:54,490 ‫As you can see, it returns a float here. 26 00:01:54,670 --> 00:02:01,210 ‫So we call the EPS function and here I transform the position of my self. 27 00:02:01,510 --> 00:02:09,060 ‫So this dot transform dot position and subtract the position of the ball. 28 00:02:09,070 --> 00:02:17,440 ‫So ball to transform the position thought y and I should use y by my by my own as well. 29 00:02:17,440 --> 00:02:24,730 ‫I calculate the y value of the racquet of player two minus the y value of the ball. 30 00:02:25,870 --> 00:02:32,140 ‫And if that value is higher than 50, then do the following. 31 00:02:32,200 --> 00:02:36,670 ‫So first check if the ball is higher than the record. 32 00:02:36,680 --> 00:02:46,480 ‫So if transform dot position that y is higher than ball, don't transform that position y. 33 00:02:49,690 --> 00:02:53,290 ‫If that's the case, then get the component. 34 00:02:53,290 --> 00:02:58,060 ‫Rigid body rigid body to DH. 35 00:03:00,830 --> 00:03:14,690 ‫And change its velocity to a new vector two, which is zero comma one, and the one means the y value 36 00:03:14,690 --> 00:03:19,310 ‫is positive times, the movement speed. 37 00:03:20,060 --> 00:03:23,270 ‫So in this case, it just says if the ball. 38 00:03:24,790 --> 00:03:29,470 ‫Because further than 50 points higher than our record. 39 00:03:29,500 --> 00:03:35,530 ‫Please move the record up and else please move it down. 40 00:03:35,530 --> 00:03:41,260 ‫So we just copy that code here, we enter it there and now we use minus one. 41 00:03:42,730 --> 00:03:44,470 ‫So now please move it down. 42 00:03:45,880 --> 00:03:53,470 ‫And if this statement here is not true, then we have an LS and here we just say, please don't move 43 00:03:53,470 --> 00:03:54,130 ‫at all. 44 00:03:54,880 --> 00:04:01,810 ‫So we say get component and we reduce this movement speed here and enter zero. 45 00:04:01,810 --> 00:04:10,180 ‫So that means the velocity of our racquet will be zero whenever the distance from the ball to the racket 46 00:04:10,180 --> 00:04:12,390 ‫is lower than 50. 47 00:04:12,550 --> 00:04:15,070 ‫Not the distance in general, but the Y position distance. 48 00:04:15,340 --> 00:04:15,790 ‫All right. 49 00:04:15,790 --> 00:04:18,280 ‫So now that we have that, we can save that script. 50 00:04:18,400 --> 00:04:26,110 ‫We can deactivate our racket player to script, change the movement speed of our eye. 51 00:04:26,920 --> 00:04:29,920 ‫So let's save the scene and then we will see. 52 00:04:29,920 --> 00:04:32,140 ‫Okay, here, movement speed. 53 00:04:32,440 --> 00:04:36,880 ‫Let's do 200 and let's drag the ball in there as well. 54 00:04:37,900 --> 00:04:38,290 ‫All right. 55 00:04:38,290 --> 00:04:39,580 ‫So now let's check it out. 56 00:04:43,540 --> 00:04:44,590 ‫The ball moves. 57 00:04:44,590 --> 00:04:47,680 ‫And as you can see, the I, I don't press anything. 58 00:04:47,680 --> 00:04:56,920 ‫The eye follows along and whenever it's 50 points or higher, then it moves along and then we are game 59 00:04:56,920 --> 00:04:57,310 ‫over. 60 00:04:57,850 --> 00:04:58,420 ‫Great. 61 00:04:58,420 --> 00:05:02,350 ‫So we have an eye for our play to and that's great. 62 00:05:02,350 --> 00:05:05,860 ‫So now you know how to create a very, very basic eye. 63 00:05:06,220 --> 00:05:12,190 ‫It's even too much, almost to call it an eye, but it does something on its own based on the input 64 00:05:12,190 --> 00:05:13,060 ‫that it gets. 65 00:05:13,330 --> 00:05:14,020 ‫Great. 66 00:05:14,290 --> 00:05:17,230 ‫So see you in the next chapter where we create the next game.