1 00:00:03,950 --> 00:00:04,770 ‫We'll come back. 2 00:00:04,790 --> 00:00:07,730 ‫In this video, we will have a look at the rigid body. 3 00:00:07,790 --> 00:00:13,850 ‫And therefore, what I'll do first is save my scene. 4 00:00:13,850 --> 00:00:20,210 ‫So let's save the scene as and I'm going to call that main because what we haven't done yet is save 5 00:00:20,210 --> 00:00:23,120 ‫scenes and you should that should do that regularly. 6 00:00:23,120 --> 00:00:24,710 ‫So you should save your scene. 7 00:00:24,710 --> 00:00:27,740 ‫And now you can see that here it says Main now. 8 00:00:27,890 --> 00:00:33,410 ‫So whenever you make a change and you want to keep that, you always should press control, save. 9 00:00:33,410 --> 00:00:36,290 ‫Or you could go here to save scenes. 10 00:00:37,070 --> 00:00:37,430 ‫All right. 11 00:00:37,430 --> 00:00:42,620 ‫So now let's go ahead and choose our player, because he already has a rigid body. 12 00:00:42,620 --> 00:00:46,370 ‫And as I said, there are multiple different properties. 13 00:00:46,370 --> 00:00:48,740 ‫We only had to look at use gravity yet. 14 00:00:48,890 --> 00:00:55,610 ‫So now let's have a look at the mass, for example, and therefore I would like to make our world a 15 00:00:55,610 --> 00:00:56,330 ‫bit bigger. 16 00:00:56,330 --> 00:01:01,070 ‫So I'm going to scale the underground up to five, five and five. 17 00:01:01,100 --> 00:01:03,170 ‫Actually, the Y value can stay one. 18 00:01:03,560 --> 00:01:06,020 ‫It doesn't matter because it doesn't really have a height. 19 00:01:06,110 --> 00:01:07,160 ‫Our plane. 20 00:01:07,400 --> 00:01:10,070 ‫So now let's have a look at our game mode. 21 00:01:10,070 --> 00:01:11,180 ‫All right, that's good. 22 00:01:11,180 --> 00:01:18,710 ‫And now I would like to use my own layout, which allows me to see my game from the scene view and the 23 00:01:18,710 --> 00:01:19,310 ‫game view. 24 00:01:19,310 --> 00:01:24,740 ‫At the same time here 2D is activated, so now I can only see the game from a 2D angle. 25 00:01:24,740 --> 00:01:26,210 ‫So I'm going to change that. 26 00:01:26,210 --> 00:01:31,430 ‫I'm deactivating this to two D button and now I can see it here as well. 27 00:01:31,430 --> 00:01:34,640 ‫So that can be useful in some occasions. 28 00:01:34,970 --> 00:01:35,360 ‫All right. 29 00:01:35,360 --> 00:01:38,180 ‫So now that is my game and my ball. 30 00:01:38,180 --> 00:01:39,980 ‫And now let's move the ball. 31 00:01:39,980 --> 00:01:41,090 ‫Let's run the game. 32 00:01:42,260 --> 00:01:44,570 ‫And as you can see, the ball is moving. 33 00:01:44,780 --> 00:01:49,220 ‫So now I'm activating or opening my hierarchy view. 34 00:01:49,220 --> 00:01:50,630 ‫I'm going to go to player. 35 00:01:51,020 --> 00:01:54,920 ‫And what I can do here is, for example, change the mass. 36 00:01:54,920 --> 00:02:00,830 ‫So if I change the mass to 2000 now and I'm going to pause the game, I'm going to change the mass to 37 00:02:00,830 --> 00:02:03,950 ‫2000, I'm going to start the game again. 38 00:02:06,220 --> 00:02:16,690 ‫And now I can barely move my ball, or even not at all, because my force that I'm applying is way too 39 00:02:16,690 --> 00:02:19,120 ‫little, or actually just a little bit. 40 00:02:19,210 --> 00:02:21,700 ‫I can move the ball very, very slowly. 41 00:02:21,700 --> 00:02:27,580 ‫So I'm applying the force, and that has to do with the speed and the mass, of course. 42 00:02:27,580 --> 00:02:32,890 ‫So the speed applies, some force multiplied with whether we press forward or backward. 43 00:02:32,890 --> 00:02:42,370 ‫So if I extend the speed to, let's say, 200 now, my ball will start to move after a while because 44 00:02:42,400 --> 00:02:47,020 ‫200 is enough force for the ball to be moving. 45 00:02:47,200 --> 00:02:49,150 ‫But it moves super slowly, as you can see here. 46 00:02:49,930 --> 00:02:50,260 ‫All right. 47 00:02:50,260 --> 00:02:56,710 ‫And then if I try to go backward or it's too too hard, if I change the mass to one again, now you 48 00:02:56,710 --> 00:02:59,710 ‫can see, whoa, the ball is moving super duper fast. 49 00:03:00,130 --> 00:03:03,460 ‫And it fell off my screen or my my area. 50 00:03:03,460 --> 00:03:13,420 ‫Even so, if I change the mass to one again and my speed to, let's say 50 and let's start the game 51 00:03:13,420 --> 00:03:13,960 ‫again. 52 00:03:16,410 --> 00:03:24,390 ‫Now my ball will be much, much faster and it will constantly apply force so that the ball will become 53 00:03:24,570 --> 00:03:26,310 ‫faster and faster and faster. 54 00:03:26,490 --> 00:03:28,380 ‫And that's something that you can change. 55 00:03:28,380 --> 00:03:35,880 ‫So you can add and drag to your ball or to your game object so that the speed is limited. 56 00:03:35,880 --> 00:03:38,760 ‫So let's add a drag of ten, as you can see. 57 00:03:38,760 --> 00:03:43,770 ‫Now, my ball, even if I'm pressing for a long time, it will not exceed a specific speed. 58 00:03:43,770 --> 00:03:51,210 ‫So that's the speed that it goes with and it can't go any faster because it has a drag assigned to it. 59 00:03:51,270 --> 00:03:53,220 ‫It's the same thing with the angular drag. 60 00:03:53,220 --> 00:03:58,710 ‫If I want to change the rotation speed of my object, I could change the angular drag here. 61 00:03:58,740 --> 00:03:59,730 ‫Now use gravity. 62 00:03:59,730 --> 00:04:00,630 ‫We've seen that. 63 00:04:00,630 --> 00:04:06,390 ‫If we activate that, then we use the gravity so our ball can fall off. 64 00:04:07,160 --> 00:04:08,150 ‫Or it fall down. 65 00:04:08,150 --> 00:04:10,340 ‫As you can see now, it falls down slowly. 66 00:04:12,440 --> 00:04:17,370 ‫And if I deactivate the gravity, my ball will stay in the air. 67 00:04:17,390 --> 00:04:19,030 ‫As you can see now, it's still in the air. 68 00:04:19,040 --> 00:04:20,660 ‫You can see it here even better. 69 00:04:21,380 --> 00:04:25,040 ‫Let's use gravity and but we still can move our ball. 70 00:04:25,040 --> 00:04:29,390 ‫As you can see, it doesn't apply any gravity, but we can still move the ball. 71 00:04:29,870 --> 00:04:34,640 ‫However, if we apply is kinematic, we cannot move the ball anymore. 72 00:04:34,670 --> 00:04:35,780 ‫So what is kinetic? 73 00:04:35,780 --> 00:04:43,160 ‫Does it will deactivate any kind of movement so it's not influenced by the physics world anymore, which 74 00:04:43,160 --> 00:04:49,610 ‫means adding force within our player movement script does not do anything because as I said, it doesn't 75 00:04:49,610 --> 00:04:51,350 ‫care about the physics world anymore. 76 00:04:52,580 --> 00:04:54,200 ‫All right, so it's kinematic. 77 00:04:54,200 --> 00:05:01,010 ‫We can use that for walls if we don't want them to be influenced by physics, but still be walls. 78 00:05:01,010 --> 00:05:08,990 ‫So still be a force to reckon with or something that just stops our player or our game object. 79 00:05:09,230 --> 00:05:11,360 ‫Then we can use interpolate. 80 00:05:11,360 --> 00:05:19,130 ‫As I explained in the last video, that's for the case that you animate your player and you want it 81 00:05:19,130 --> 00:05:21,050 ‫to be dependent on the physics world. 82 00:05:21,050 --> 00:05:23,720 ‫So that could be important if you use that. 83 00:05:23,720 --> 00:05:26,900 ‫So then you could use interpolate or extrapolate. 84 00:05:27,080 --> 00:05:35,330 ‫Then the collision detection is discrete by default, which is most of the time completely fine. 85 00:05:35,360 --> 00:05:40,820 ‫Continuous dynamic is if you have super fast movement, then you want the collision detection to be 86 00:05:40,820 --> 00:05:41,690 ‫extremely fast. 87 00:05:41,690 --> 00:05:47,150 ‫Then continuous dynamic is the better choice and otherwise continuous is fine as well. 88 00:05:47,150 --> 00:05:53,780 ‫So continuous dynamic is for very, very fast games where physics is very important and goes very quickly. 89 00:05:53,780 --> 00:06:01,430 ‫But as I said, discrete is is fine for most of the cases and it's also the best in terms of resources. 90 00:06:01,730 --> 00:06:04,190 ‫And finally, let's have a look at constraints. 91 00:06:04,190 --> 00:06:07,100 ‫You can freeze positions and freeze rotations. 92 00:06:07,100 --> 00:06:14,630 ‫So, for example, if I choose my player and now I move my player to the top and I wanted to not go 93 00:06:14,630 --> 00:06:20,750 ‫down, of course I could use use gravity or I can simply activate freeze position y. 94 00:06:20,750 --> 00:06:25,220 ‫So now the y position will be frozen and our ball will never fall off. 95 00:06:25,700 --> 00:06:31,190 ‫We can still move it, but the y position is simply fixed and we can even activate gravity. 96 00:06:31,280 --> 00:06:34,790 ‫It will not influence our ball because the y position is. 97 00:06:35,780 --> 00:06:37,490 ‫Fixed or is frozen. 98 00:06:37,820 --> 00:06:40,160 ‫Now the same thing goes with the X position. 99 00:06:40,220 --> 00:06:43,640 ‫So that means now I can move the ball downwards. 100 00:06:43,670 --> 00:06:49,310 ‫Let's activate gravity, but I cannot move it to the right and left. 101 00:06:50,150 --> 00:06:53,060 ‫I can only move it backwards and forwards. 102 00:06:54,890 --> 00:06:56,270 ‫Same goes with the Z position. 103 00:06:56,270 --> 00:07:03,440 ‫So if I activate that and I deactivate the X position now, I can not move forward. 104 00:07:04,740 --> 00:07:06,930 ‫Actually, it's not used. 105 00:07:06,960 --> 00:07:07,820 ‫It doesn't use gravity. 106 00:07:07,830 --> 00:07:09,510 ‫So now I cannot go forward. 107 00:07:09,510 --> 00:07:12,000 ‫I can only go to the left and to the right. 108 00:07:13,380 --> 00:07:14,990 ‫Same goes with the rotation. 109 00:07:15,000 --> 00:07:20,960 ‫So in our case we have this little ball, so or this little player. 110 00:07:20,970 --> 00:07:27,410 ‫Let's give him another 3D object which can be, let's say, a cube. 111 00:07:27,420 --> 00:07:35,340 ‫So I wanted to have a little cube on top of it and I'm going to make it 0.2 and oh point. 112 00:07:36,390 --> 00:07:38,760 ‫Well, actually, let's use one here. 113 00:07:41,350 --> 00:07:42,820 ‫Now you can see it better. 114 00:07:43,120 --> 00:07:44,530 ‫So now that's our ball. 115 00:07:45,430 --> 00:07:49,810 ‫Let's click on the player and let's activate gravity again. 116 00:07:49,930 --> 00:07:54,130 ‫So if I move to the left and right, as you can see, it rotates. 117 00:07:55,120 --> 00:08:03,670 ‫And now even even flies sometimes, because as you can see, the cube changes the behavior of our ball 118 00:08:04,690 --> 00:08:06,310 ‫relatively quickly. 119 00:08:06,430 --> 00:08:11,330 ‫And what you can do is freeze the rotation towards X, for example. 120 00:08:11,350 --> 00:08:15,820 ‫Now, it will only rotate in a certain direction. 121 00:08:16,210 --> 00:08:18,970 ‫Let's freeze the rotation towards Y as well. 122 00:08:18,970 --> 00:08:27,610 ‫As you can see, the Y rotation is not influenced anymore, so our ball only rotates towards the z coordinate 123 00:08:27,610 --> 00:08:28,330 ‫currently. 124 00:08:29,620 --> 00:08:33,520 ‫And if I deactivate that as well now, it will not rotate anymore. 125 00:08:33,910 --> 00:08:41,470 ‫It will only move around in our physics world, which might be the behavior that you want to have. 126 00:08:41,830 --> 00:08:48,880 ‫So what can happen is if you have an object that could fall off and if you don't have the functionality 127 00:08:48,880 --> 00:08:54,490 ‫program that it stands up again, what you can do is freeze rotation so it will never fall down or fall 128 00:08:54,490 --> 00:08:56,450 ‫forward or to decide something. 129 00:08:56,470 --> 00:08:59,080 ‫So you could freeze rotations for that. 130 00:08:59,830 --> 00:09:00,430 ‫All right. 131 00:09:00,430 --> 00:09:02,380 ‫So that's about the rigid body. 132 00:09:02,770 --> 00:09:08,770 ‫It's really important if you want to impact anything via physics, it needs to have a rigid body, otherwise 133 00:09:08,770 --> 00:09:09,730 ‫it won't work. 134 00:09:10,180 --> 00:09:10,750 ‫All right. 135 00:09:11,020 --> 00:09:14,140 ‫So I'm going to get rid of the cube again. 136 00:09:14,140 --> 00:09:18,640 ‫As you can see, you can get some very funny behavior with your ball here, with your player if you 137 00:09:18,640 --> 00:09:20,920 ‫add a cube to it or if you change the shape. 138 00:09:20,920 --> 00:09:24,760 ‫So please go ahead and play with it and have some fun. 139 00:09:24,760 --> 00:09:28,990 ‫And yeah, in the next video we will have a look at the colliders. 140 00:09:28,990 --> 00:09:32,770 ‫So there are different types of colliders and we're going to have a look at the most important ones. 141 00:09:32,770 --> 00:09:34,900 ‫So see you there, by the way. 142 00:09:34,900 --> 00:09:36,340 ‫Don't forget to save your scene. 143 00:09:36,670 --> 00:09:38,050 ‫So see you in the next video.