1 00:00:04,120 --> 00:00:05,530 ‫Back in this video. 2 00:00:05,530 --> 00:00:07,980 ‫We are going to take care of our ball. 3 00:00:07,990 --> 00:00:11,800 ‫So far, our ball is really just this little square here in the middle. 4 00:00:11,800 --> 00:00:18,010 ‫And we need to change the functionality or we need to add functionality to him so that it flies from 5 00:00:18,010 --> 00:00:21,760 ‫left to right, back and forth whenever it hits a record. 6 00:00:21,760 --> 00:00:25,180 ‫And of course, we also want to have this bounce in it. 7 00:00:25,180 --> 00:00:29,590 ‫So it should bounce off the racquets and bounce off the top and the bottom wall. 8 00:00:30,370 --> 00:00:32,710 ‫It shouldn't bounce off the sidewalls for now. 9 00:00:32,710 --> 00:00:36,340 ‫But we will add that functionality just for testing purposes right now. 10 00:00:36,490 --> 00:00:44,980 ‫So let's go ahead and change our field as our ball needs to have a collider, which it does. 11 00:00:44,980 --> 00:00:47,740 ‫And what we need to add is a material. 12 00:00:47,740 --> 00:00:51,010 ‫So far we have no physical material for our ball. 13 00:00:51,010 --> 00:00:53,560 ‫So what it is right now is simply a collision dot. 14 00:00:53,560 --> 00:00:57,340 ‫So that means that if something goes towards the ball, it will collide with it. 15 00:00:57,460 --> 00:01:00,880 ‫If you want the ball to move, we need to add a rigid body. 16 00:01:00,880 --> 00:01:04,270 ‫If we want the ball to bounce, we need to add a physical material. 17 00:01:04,390 --> 00:01:08,260 ‫So let's go ahead and create the rigid body first. 18 00:01:08,260 --> 00:01:11,260 ‫So I'm just going to add a physics to the effect. 19 00:01:11,800 --> 00:01:16,990 ‫And if I want to do that, if I want to use a physics to defect effect, for example, a rigid body 20 00:01:16,990 --> 00:01:18,940 ‫to DX, I will run it to an error. 21 00:01:18,940 --> 00:01:19,870 ‫So let's try that. 22 00:01:19,870 --> 00:01:26,380 ‫You can see I can't add due to a conflicting component, which means our Box Collider currently is a 23 00:01:26,380 --> 00:01:34,720 ‫3D box collider and a 3D box collider can't work with a 2D rigid body or with other 2D components. 24 00:01:34,720 --> 00:01:41,860 ‫So that means we need to remove that component, remove our box collider and add a 2D box collider. 25 00:01:41,860 --> 00:01:48,400 ‫So there is a 2D box collider here, as you can see, and that's what we want to use now as the offset. 26 00:01:48,400 --> 00:01:50,530 ‫There is a very small value here. 27 00:01:50,530 --> 00:01:53,920 ‫I don't want to have any offset at all, so let's get rid of that. 28 00:01:55,420 --> 00:02:01,480 ‫So I go for zero here and now I will add a 2D rigid body. 29 00:02:01,480 --> 00:02:08,620 ‫So rigid body 2D, which is the component which adds, for example, gravity, it adds a mass. 30 00:02:08,770 --> 00:02:11,410 ‫Well, pretty much it makes it a physical object. 31 00:02:11,410 --> 00:02:16,570 ‫So now it's not just the wall, pretty much what the ball was before with its collider. 32 00:02:16,570 --> 00:02:22,900 ‫But now it's actually a physical object which can be dragged down by gravity, which can be influenced 33 00:02:22,900 --> 00:02:24,640 ‫by physics. 34 00:02:25,510 --> 00:02:29,650 ‫So now let's go ahead and create a physics material. 35 00:02:29,770 --> 00:02:30,700 ‫Let's go with that. 36 00:02:30,760 --> 00:02:37,880 ‫So we go back to our assets, we go to materials, and I'm going to create a new physics material to 37 00:02:37,900 --> 00:02:38,380 ‫DX. 38 00:02:40,250 --> 00:02:42,290 ‫And I'm going to call that one bull. 39 00:02:43,220 --> 00:02:46,180 ‫You could, of course, call it ball physics material or something like that. 40 00:02:46,190 --> 00:02:47,730 ‫I'm just going to keep it simple. 41 00:02:47,750 --> 00:02:50,660 ‫That's the physics material that I want to use for my ball. 42 00:02:50,690 --> 00:02:56,480 ‫Now that physics material has two different values one of one for friction and one for punchiness. 43 00:02:56,510 --> 00:02:59,090 ‫The friction is pretty much how. 44 00:02:59,270 --> 00:03:06,020 ‫How much does it wear of how much does the speed wear off when it, for example, rolls or slides over 45 00:03:06,020 --> 00:03:07,130 ‫another surface? 46 00:03:07,580 --> 00:03:14,120 ‫As we don't want to reduce the speed of our ball at all, we need the friction of zero. 47 00:03:14,810 --> 00:03:20,630 ‫Now, the bounce in this means how fast or how strongly does it bounce back when it falls against a 48 00:03:20,630 --> 00:03:21,790 ‫different collider? 49 00:03:21,800 --> 00:03:28,100 ‫And here we need one because we want the ball to go with the same speed afterwards. 50 00:03:28,220 --> 00:03:29,840 ‫We could, of course, say 1.1. 51 00:03:29,840 --> 00:03:32,720 ‫That means that each time it bounces, it goes faster. 52 00:03:32,720 --> 00:03:33,920 ‫But that's not what we want. 53 00:03:33,950 --> 00:03:36,230 ‫We want to go for 1/1. 54 00:03:36,980 --> 00:03:41,660 ‫So now that we have the physics material for our ball, we can drag it into its box. 55 00:03:41,660 --> 00:03:44,510 ‫Collider So let's drag that right in there. 56 00:03:46,290 --> 00:03:52,590 ‫So if we test that now and I'm going to use a gravity scale of 100 to speed it up a little bit, we 57 00:03:52,590 --> 00:03:56,040 ‫will see that our ball will not do nothing. 58 00:03:56,040 --> 00:04:00,660 ‫Well, it will drop, but it will not collide with the bottom, not with the bottom wall, at least. 59 00:04:00,660 --> 00:04:07,140 ‫And that's because our bottom wall as other walls has a box collider and not a box collider. 60 00:04:07,140 --> 00:04:12,480 ‫2D because our ball has a box collider two D It doesn't collide with 3D colliders. 61 00:04:12,480 --> 00:04:14,820 ‫It really doesn't care about those three D colliders. 62 00:04:14,820 --> 00:04:16,890 ‫It only cares about 2D colliders. 63 00:04:16,890 --> 00:04:21,180 ‫So what we need to do is replace the colliders of all of our walls. 64 00:04:21,180 --> 00:04:28,080 ‫So I'm going to remove that component and I'm going to add a physics to the Box Collider component. 65 00:04:28,080 --> 00:04:34,290 ‫And that's what I'm going to do with the wall, top wall, bottom wall left wall right and wall left. 66 00:04:34,290 --> 00:04:41,190 ‫So let's remove that component, add a box collider and do the same thing for all of them. 67 00:04:41,370 --> 00:04:50,910 ‫And next, physics two D Box Collider and same here remove component box collider two DX Add Component 68 00:04:50,910 --> 00:04:53,070 ‫Box Collider to DX. 69 00:04:54,120 --> 00:04:54,720 ‫All right. 70 00:04:54,720 --> 00:04:59,370 ‫So if we test that now, our ball should bounce off. 71 00:04:59,670 --> 00:05:07,200 ‫As you can see, it bounces off our bottom wall and it does that with exactly the same speed as it did 72 00:05:07,200 --> 00:05:07,590 ‫before. 73 00:05:07,590 --> 00:05:09,330 ‫So it's influenced by gravity now. 74 00:05:09,330 --> 00:05:10,080 ‫That's good. 75 00:05:10,080 --> 00:05:14,760 ‫We will need to change that later on, as soon as our ball flies from left to right. 76 00:05:15,060 --> 00:05:21,000 ‫So now what we could do is, for example, just for your taste testing purposes, we could change the 77 00:05:21,210 --> 00:05:24,240 ‫bounce in to 1.5, for example. 78 00:05:24,490 --> 00:05:32,130 ‫Now we see our ball bounces off faster than it did before and it drops down, drops off our map as well. 79 00:05:32,130 --> 00:05:34,380 ‫So let's go back to bounce in this one. 80 00:05:35,550 --> 00:05:39,150 ‫So it will bounce off the same speed and height that it did before. 81 00:05:40,590 --> 00:05:45,990 ‫Now that we have seen that we need to dx physics colliders for our the objects that need to be influenced 82 00:05:45,990 --> 00:05:46,800 ‫by the ball. 83 00:05:46,800 --> 00:05:49,740 ‫We need to do the same thing with our rackets. 84 00:05:49,740 --> 00:05:53,130 ‫So let's go with the records or change the records. 85 00:05:53,130 --> 00:05:55,620 ‫Here we have a box collider here. 86 00:05:55,620 --> 00:05:58,740 ‫We need to change that to being a box collider to DX. 87 00:05:59,730 --> 00:06:07,920 ‫The same thing with the record to remove the component and add the component physics to the box. 88 00:06:07,920 --> 00:06:12,690 ‫Collider So now you see those weird offset numbers and those values. 89 00:06:12,690 --> 00:06:18,240 ‫What really matters is that the collider has the same size as the game object itself. 90 00:06:18,360 --> 00:06:19,350 ‫That's what we get here. 91 00:06:19,350 --> 00:06:24,870 ‫So let's reduce the offset, change the size to one and do the same thing. 92 00:06:24,870 --> 00:06:31,140 ‫For our record, we don't need any offset and we just change it to one times one. 93 00:06:31,560 --> 00:06:38,880 ‫Now our ball should bounce off the records and in order for our ball to fly from left to right, we 94 00:06:38,880 --> 00:06:40,620 ‫need to add a script to the ball. 95 00:06:40,620 --> 00:06:46,080 ‫Because so far it only is influenced by physics, which is based on this gravity scale that we have 96 00:06:46,080 --> 00:06:48,990 ‫here, and we are going to change that in the next video. 97 00:06:48,990 --> 00:06:54,960 ‫So let's go to the next video where we will add the script to our ball so that it flies left and right. 98 00:06:54,960 --> 00:06:56,280 ‫See you in the next video.