All language subtitles for 10. Implement 2D Collision

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 1 00:00:00,000 --> 00:00:04,095 [MUSIC] 2 2 00:00:04,095 --> 00:00:07,460 In this video, we're going to add a collision and rigid body to our player. 3 3 00:00:07,460 --> 00:00:10,520 We are going to add some collision to our environment so 4 4 00:00:10,520 --> 00:00:11,880 that we can drop our player. 5 5 00:00:11,880 --> 00:00:16,020 And he goes, oop, clunk, and lands on our world. 6 6 00:00:16,020 --> 00:00:18,920 Okay, let's jump in and talk collisions. 7 7 00:00:18,920 --> 00:00:19,700 This is a good time for 8 8 00:00:19,700 --> 00:00:24,030 us to prefab our player, dragging it down into our assets folder down here. 9 9 00:00:24,030 --> 00:00:27,470 Time to create a prefab itself as well, I think, so 10 10 00:00:27,470 --> 00:00:31,210 that we can keep our prefabs nice and tidy as we start to create them. 11 11 00:00:31,210 --> 00:00:33,150 Put our player into there. 12 12 00:00:33,150 --> 00:00:36,310 It's good to be considering your player as a prefab as you go along, 13 13 00:00:36,310 --> 00:00:39,770 cuz when we start to have multiple levels, we need to make sure that anything we do 14 14 00:00:39,770 --> 00:00:45,130 in the player is gonna be fine and dandy as we go through those various levels. 15 15 00:00:45,130 --> 00:00:47,940 Okay, when we look at our player, the first thing we need to do is to make sure 16 16 00:00:47,940 --> 00:00:50,590 that the player has some sort of collision. 17 17 00:00:50,590 --> 00:00:54,980 And some sort of rigidbody so that we can apply forces to it, so add a component 18 18 00:00:54,980 --> 00:01:00,160 first of all add rigidbody, rigidbody, and we'll add rigidbody 2D in this whole 19 19 00:01:00,160 --> 00:01:03,750 section of the course you'll see that we're looking for the 2D option in each of 20 20 00:01:03,750 --> 00:01:08,850 these, very similar to regular 3D rigidbody but rigidbody 2D. 21 21 00:01:08,850 --> 00:01:12,340 We have under body type dynamic, kinematic, and static. 22 22 00:01:12,340 --> 00:01:14,120 I want to take just a brief moment, 23 23 00:01:14,120 --> 00:01:17,910 if you haven't already got those embedded in your mind what they mean. 24 24 00:01:17,910 --> 00:01:21,244 That we have in terms of rigidbodies, the rigidbody 25 25 00:01:21,244 --> 00:01:26,019 component brings the game object under the forces of the physics engine and 26 26 00:01:26,019 --> 00:01:29,910 because it's 2D, it's only moving on the x y axis. 27 27 00:01:29,910 --> 00:01:33,370 The body types dynamic means that gravity and 28 28 00:01:33,370 --> 00:01:36,990 physics forces will apply to this game object. 29 29 00:01:36,990 --> 00:01:40,130 If we change that to kinematic, it means it has infinite mass. 30 30 00:01:40,130 --> 00:01:44,170 If its kinematic, it has infinite mass which means that we have to push it 31 31 00:01:44,170 --> 00:01:47,900 from point to point, we can't rely on the physics of the gravity to do that, 32 32 00:01:47,900 --> 00:01:50,000 gravity just won't apply. 33 33 00:01:50,000 --> 00:01:54,600 And if we have it as static it means it has collisions but no movement. 34 34 00:01:54,600 --> 00:01:59,460 And we talked about, Ben and I talked about, what is the right sort of 35 35 00:01:59,460 --> 00:02:03,460 rigidbody to have for our player and we think that dynamic rigidbody is gonna be 36 36 00:02:03,460 --> 00:02:06,360 more interesting so we can play around with some of the physics. 37 37 00:02:06,360 --> 00:02:09,360 We can have it bounce and jump and boing and slide and 38 38 00:02:09,360 --> 00:02:13,070 all that kind of good stuff to play around with a different aspect of Unity so 39 39 00:02:13,070 --> 00:02:16,550 that's we're going to set up our character so if we have a look at our rigid body. 40 40 00:02:16,550 --> 00:02:21,378 It's already on dynamic and the second thing that we need in here in order for 41 41 00:02:21,378 --> 00:02:25,165 our character to be colliding with the world is a collider. 42 42 00:02:25,165 --> 00:02:32,304 So we will go for a, I think we use a captural collider 2D. 43 43 00:02:32,304 --> 00:02:36,120 It's a little neater having a capsule collider than having a box. 44 44 00:02:36,120 --> 00:02:37,380 Let's have a look at that. 45 45 00:02:37,380 --> 00:02:40,280 So if I click on the player and then zoom in, 46 46 00:02:40,280 --> 00:02:42,710 we can see it's just a big circle at the moment, not so good. 47 47 00:02:42,710 --> 00:02:44,450 I need to play around with that a little bit. 48 48 00:02:44,450 --> 00:02:46,520 Shrink it in a touch. 49 49 00:02:46,520 --> 00:02:48,170 Lower it down. 50 50 00:02:48,170 --> 00:02:52,010 The goal here is to have it pretty much where the player's feet are at that 51 51 00:02:52,010 --> 00:02:54,960 point so there's no discernible difference. 52 52 00:02:54,960 --> 00:02:58,540 And because our frames of animation are going to bounce around a little bit, 53 53 00:02:58,540 --> 00:03:01,660 we don't need to have it exactly, exactly precise, but pretty good. 54 54 00:03:01,660 --> 00:03:05,099 I think that's a little bit narrower. 55 55 00:03:05,099 --> 00:03:09,613 And how is it height wise, too high so shrink down a little bit, also drop it 56 56 00:03:09,613 --> 00:03:14,502 down a little bit just raising it lowering it here, I think that's pretty good. 57 57 00:03:14,502 --> 00:03:19,551 The feet might be a tiny bit under there so we will end up with, 58 58 00:03:19,551 --> 00:03:24,702 I think I need to type this in manually .6432 there we go. 59 59 00:03:24,702 --> 00:03:30,278 So I've got an Offset of -.06 on the X and -.12 on the Y, 60 60 00:03:30,278 --> 00:03:36,816 and Size of .45 on the X and .77 on the Y that's what I've got there. 61 61 00:03:36,816 --> 00:03:40,398 We could make it a little bit higher, a little bit more to the right I think, but 62 62 00:03:40,398 --> 00:03:42,700 that is decent for now, so now we have a Collider. 63 63 00:03:42,700 --> 00:03:44,580 If we click play, what happens? 64 64 00:03:44,580 --> 00:03:47,540 You can probably guess, our player is going to go, zoink. 65 65 00:03:47,540 --> 00:03:50,820 It has gravity, but there's nothing for it to actually land on. 66 66 00:03:50,820 --> 00:03:53,060 So this is where I'd like to give you a challenge. 67 67 00:03:54,170 --> 00:03:56,390 That challenge is, make your player land. 68 68 00:03:56,390 --> 00:04:00,300 Set up the capsule collider and RigidBody on the player as we've just done. 69 69 00:04:00,300 --> 00:04:04,730 Set up Collision on your environment and go for what works. 70 70 00:04:04,730 --> 00:04:07,540 When we come back in I'm going to show you a trick 71 71 00:04:07,540 --> 00:04:10,920 that will make your tile collision even more awesome. 72 72 00:04:10,920 --> 00:04:12,690 Here's a change for you to dig around and 73 73 00:04:12,690 --> 00:04:17,660 see if you can figure out how best to add collision with the set up that we've got. 74 74 00:04:17,660 --> 00:04:19,070 With the tile map set up that we've got, 75 75 00:04:19,070 --> 00:04:22,810 a little bit of investigative journalism for you here. 76 76 00:04:22,810 --> 00:04:26,528 And to have the player drop and land without falling over, so there's 77 77 00:04:26,528 --> 00:04:30,499 a challenge for you jump in and see if your ready to take on that challenge and 78 78 00:04:30,499 --> 00:04:33,228 I'll come back with my solution when you are back. 79 79 00:04:35,381 --> 00:04:39,189 Right so we've got our player set up next we need to jump over to our tile map grid, 80 80 00:04:39,189 --> 00:04:42,944 I'm going to click on full ground the background doesn't need collision it's 81 81 00:04:42,944 --> 00:04:44,904 just there for good looks of the moment but 82 82 00:04:44,904 --> 00:04:47,370 we need to have something on the fore ground. 83 83 00:04:47,370 --> 00:04:49,750 The fore ground needs to have a couple of components. 84 84 00:04:49,750 --> 00:04:52,960 First of all we need to have, jump over in the components, 85 85 00:04:52,960 --> 00:04:58,660 a tile map Collider 2D nicely set up for us, where it immediately 86 86 00:04:58,660 --> 00:05:02,900 applies to anything that is a tile that's being painted onto the tile map. 87 87 00:05:02,900 --> 00:05:04,670 And you can see it set it up as a grid. 88 88 00:05:04,670 --> 00:05:08,080 So you might have got to that point and said, yes i'm done this is amazing. 89 89 00:05:08,080 --> 00:05:12,110 One thing that you'll find is that, if I scroll in all the way here there's 90 90 00:05:12,110 --> 00:05:16,320 a miniscule, tiny, tiny, tiny, tiny, tiny, can you see that in there? 91 91 00:05:16,320 --> 00:05:17,970 Wonder hoe far it's gonna let me go. 92 92 00:05:17,970 --> 00:05:21,100 Between this collision on the right and that collision on the left, 93 93 00:05:21,100 --> 00:05:23,980 there's just a tiny fraction different. 94 94 00:05:23,980 --> 00:05:28,100 Because we cannot get them exactly exactly the same, and that means that 95 95 00:05:28,100 --> 00:05:32,690 sometimes your player could clip into that and touch that collision. 96 96 00:05:32,690 --> 00:05:37,320 It also looks a little bit messier to have all of these boxes with all this collision 97 97 00:05:37,320 --> 00:05:42,590 and all of this information on here, so we can add to this something really cool, 98 98 00:05:42,590 --> 00:05:47,870 which is a composite collider 2D. 99 99 00:05:47,870 --> 00:05:52,750 By adding that and then going to our tile map collider 2D and saying, 100 100 00:05:52,750 --> 00:05:55,200 used by composite. 101 101 00:05:55,200 --> 00:05:59,010 It will apply one macro 102 102 00:05:59,010 --> 00:06:03,360 collision around the entirety by joining together those individual collision boxes. 103 103 00:06:03,360 --> 00:06:07,240 So you can see, it's a little bit hard to see on here, but if you have a look there, 104 104 00:06:07,240 --> 00:06:10,230 you can see the green outline goes the whole way around the outside there. 105 105 00:06:10,230 --> 00:06:15,195 If I was to turn that off in terms of the use with collision, 106 106 00:06:15,195 --> 00:06:16,600 use by composite, sorry. 107 107 00:06:16,600 --> 00:06:18,420 Turn it off, turn it back on. 108 108 00:06:18,420 --> 00:06:19,960 It's basically joining them all together. 109 109 00:06:19,960 --> 00:06:23,800 When we added that, it also added a rigidbody 2D, that's a requirement. 110 110 00:06:23,800 --> 00:06:26,333 And we are going to change the rigidbody 2D to static. 111 111 00:06:26,333 --> 00:06:30,694 We don't need it to move, we don't need it to be bouncing around in the world, 112 112 00:06:30,694 --> 00:06:35,057 it is just gonna be a static rigidbody 2D, so we have the composite collider, 113 113 00:06:35,057 --> 00:06:38,228 we have our tile map collider that is used by composite and 114 114 00:06:38,228 --> 00:06:41,168 we have our rigidbody 2D all work in harmony there. 115 115 00:06:41,168 --> 00:06:43,769 The last step is to grab our player, 116 116 00:06:43,769 --> 00:06:47,933 this is actually the second last step, grab our player, 117 117 00:06:47,933 --> 00:06:53,010 throw him up in the world, drop it down and boink not too bad at all. 118 118 00:06:53,010 --> 00:06:56,690 I say it's the second last step because when we start to move around our character 119 119 00:06:56,690 --> 00:07:01,300 we'll see something pretty interesting happening as we bump into things, 120 120 00:07:01,300 --> 00:07:03,710 our character is potentially going to rotate. 121 121 00:07:03,710 --> 00:07:10,600 So when we click on the player, jump over to the rigidbody 2D, find the constraints. 122 122 00:07:10,600 --> 00:07:14,445 And freeze the rotation on the Z Axis. 123 123 00:07:14,445 --> 00:07:15,640 Z or Z axis so 124 124 00:07:15,640 --> 00:07:19,520 that our play is not accidentally rotating around as their moving. 125 125 00:07:19,520 --> 00:07:23,550 And as a last bit of finesse, if we had a tile that wasn't exactly filling out 126 126 00:07:23,550 --> 00:07:27,170 the tile space, maybe it had a little bit of a dip in it, or an edge or 127 127 00:07:27,170 --> 00:07:32,970 a slight ramp, then what we can do is to go over into our sprite sheet. 128 128 00:07:32,970 --> 00:07:34,040 Couple of things we can do in here. 129 129 00:07:34,040 --> 00:07:38,640 If we click on our sprite sheet, go to the sprite editor, we have the ability to come 130 130 00:07:38,640 --> 00:07:41,730 into the sprite editor and then edit the physics shape. 131 131 00:07:41,730 --> 00:07:45,640 And you'll see that we have these white squares around the outside, and 132 132 00:07:45,640 --> 00:07:50,400 if I move this, then the actually physics outline is going to move for that tile. 133 133 00:07:50,400 --> 00:07:53,150 So I'll just do something a little bit crazy like that. 134 134 00:07:53,150 --> 00:07:55,300 And then apply this. 135 135 00:07:55,300 --> 00:07:56,310 Jump back into my scene. 136 136 00:07:56,310 --> 00:07:58,580 So that was applied for the corner pieces. 137 137 00:07:58,580 --> 00:08:01,760 Click on, it takes sometimes a little bit of time to update this and 138 138 00:08:01,760 --> 00:08:02,770 to see what's going on. 139 139 00:08:02,770 --> 00:08:07,150 I'll turn off our composite for the moment. 140 140 00:08:07,150 --> 00:08:09,380 So we can see that nice and clearly, use by composite. 141 141 00:08:09,380 --> 00:08:09,920 There we go. So 142 142 00:08:09,920 --> 00:08:12,550 you can see that's updated this physics shape on here 143 143 00:08:12,550 --> 00:08:14,400 to something not very elegant or very pretty. 144 144 00:08:14,400 --> 00:08:18,480 But that is how we could manipulate the individual shape of 145 145 00:08:19,520 --> 00:08:21,680 our collision on individual tiles. 146 146 00:08:21,680 --> 00:08:23,393 There's another thing we can do with the tiles. 147 147 00:08:23,393 --> 00:08:26,926 If you go to your tile assets themselves, so 148 148 00:08:26,926 --> 00:08:32,080 find something that is a .asset file, that is a tile asset, and 149 149 00:08:32,080 --> 00:08:37,051 I'll find that same piece in there, which is this Rock_0. 150 150 00:08:37,051 --> 00:08:40,440 You can see under here there's Collider Type Sprite, Grid and None. 151 151 00:08:40,440 --> 00:08:42,900 If I change this to grid, then it should say, 152 152 00:08:42,900 --> 00:08:47,880 instead of doing that funky collision physics outline I just created, 153 153 00:08:47,880 --> 00:08:52,520 it should apply just straight up grid outline on that, which it has done. 154 154 00:08:52,520 --> 00:08:55,190 And then let's check that if we use Bicomposite 155 155 00:08:55,190 --> 00:08:59,550 then it stitches it all together nice and neatly as it did before. 156 156 00:08:59,550 --> 00:09:05,620 Okay, so I'll go back and just undo the mess that I created on this tile here, 157 157 00:09:05,620 --> 00:09:09,270 that was the illustrative purposes, you don't need to go and mess up your 158 158 00:09:09,270 --> 00:09:13,040 collision like that, your physics shaped like that, is drag it back up to where it 159 159 00:09:13,040 --> 00:09:18,880 was, drag up there, right that should be nice and neat, reapply that. 160 160 00:09:18,880 --> 00:09:19,580 Good to go. 161 161 00:09:21,050 --> 00:09:24,240 So we've got our physics set up, couple of different options there. 162 162 00:09:24,240 --> 00:09:27,340 Our player, let's apply that back to to the prefab, get into that habit now. 163 163 00:09:27,340 --> 00:09:28,030 Click play, 164 164 00:09:28,030 --> 00:09:31,680 see what happens when we drop the player down to the world, clunk, perfect. 165 165 00:09:31,680 --> 00:09:35,540 We've got our player ready to go and ready to moved around in our world. 166 166 00:09:35,540 --> 00:09:39,150 Great stuff in this lecture and I'll see you in the next video. 17593

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.