All language subtitles for 10. Implement 2D Collision

af Afrikaans
ak Akan
sq Albanian
am Amharic
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

Original subtitles

1 1

[MUSIC] 2

2

In this video, we're going to add a collision and rigid body to our player. 3

3

We are going to add some collision to our environment so 4

4

that we can drop our player. 5

5

And he goes, oop, clunk, and lands on our world. 6

6

Okay, let's jump in and talk collisions. 7

7

This is a good time for 8

8

us to prefab our player, dragging it down into our assets folder down here. 9

9

Time to create a prefab itself as well, I think, so 10

10

that we can keep our prefabs nice and tidy as we start to create them. 11

11

Put our player into there. 12

12

It's good to be considering your player as a prefab as you go along, 13

13

cuz when we start to have multiple levels, we need to make sure that anything we do 14

14

in the player is gonna be fine and dandy as we go through those various levels. 15

15

Okay, when we look at our player, the first thing we need to do is to make sure 16

16

that the player has some sort of collision. 17

17

And some sort of rigidbody so that we can apply forces to it, so add a component 18

18

first of all add rigidbody, rigidbody, and we'll add rigidbody 2D in this whole 19

19

section of the course you'll see that we're looking for the 2D option in each of 20

20

these, very similar to regular 3D rigidbody but rigidbody 2D. 21

21

We have under body type dynamic, kinematic, and static. 22

22

I want to take just a brief moment, 23

23

if you haven't already got those embedded in your mind what they mean. 24

24

That we have in terms of rigidbodies, the rigidbody 25

25

component brings the game object under the forces of the physics engine and 26

26

because it's 2D, it's only moving on the x y axis. 27

27

The body types dynamic means that gravity and 28

28

physics forces will apply to this game object. 29

29

If we change that to kinematic, it means it has infinite mass. 30

30

If its kinematic, it has infinite mass which means that we have to push it 31

31

from point to point, we can't rely on the physics of the gravity to do that, 32

32

gravity just won't apply. 33

33

And if we have it as static it means it has collisions but no movement. 34

34

And we talked about, Ben and I talked about, what is the right sort of 35

35

rigidbody to have for our player and we think that dynamic rigidbody is gonna be 36

36

more interesting so we can play around with some of the physics. 37

37

We can have it bounce and jump and boing and slide and 38

38

all that kind of good stuff to play around with a different aspect of Unity so 39

39

that's we're going to set up our character so if we have a look at our rigid body. 40

40

It's already on dynamic and the second thing that we need in here in order for 41

41

our character to be colliding with the world is a collider. 42

42

So we will go for a, I think we use a captural collider 2D. 43

43

It's a little neater having a capsule collider than having a box. 44

44

Let's have a look at that. 45

45

So if I click on the player and then zoom in, 46

46

we can see it's just a big circle at the moment, not so good. 47

47

I need to play around with that a little bit. 48

48

Shrink it in a touch. 49

49

Lower it down. 50

50

The goal here is to have it pretty much where the player's feet are at that 51

51

point so there's no discernible difference. 52

52

And because our frames of animation are going to bounce around a little bit, 53

53

we don't need to have it exactly, exactly precise, but pretty good. 54

54

I think that's a little bit narrower. 55

55

And how is it height wise, too high so shrink down a little bit, also drop it 56

56

down a little bit just raising it lowering it here, I think that's pretty good. 57

57

The feet might be a tiny bit under there so we will end up with, 58

58

I think I need to type this in manually .6432 there we go. 59

59

So I've got an Offset of -.06 on the X and -.12 on the Y, 60

60

and Size of .45 on the X and .77 on the Y that's what I've got there. 61

61

We could make it a little bit higher, a little bit more to the right I think, but 62

62

that is decent for now, so now we have a Collider. 63

63

If we click play, what happens? 64

64

You can probably guess, our player is going to go, zoink. 65

65

It has gravity, but there's nothing for it to actually land on. 66

66

So this is where I'd like to give you a challenge. 67

67

That challenge is, make your player land. 68

68

Set up the capsule collider and RigidBody on the player as we've just done. 69

69

Set up Collision on your environment and go for what works. 70

70

When we come back in I'm going to show you a trick 71

71

that will make your tile collision even more awesome. 72

72

Here's a change for you to dig around and 73

73

see if you can figure out how best to add collision with the set up that we've got. 74

74

With the tile map set up that we've got, 75

75

a little bit of investigative journalism for you here. 76

76

And to have the player drop and land without falling over, so there's 77

77

a challenge for you jump in and see if your ready to take on that challenge and 78

78

I'll come back with my solution when you are back. 79

79

Right so we've got our player set up next we need to jump over to our tile map grid, 80

80

I'm going to click on full ground the background doesn't need collision it's 81

81

just there for good looks of the moment but 82

82

we need to have something on the fore ground. 83

83

The fore ground needs to have a couple of components. 84

84

First of all we need to have, jump over in the components, 85

85

a tile map Collider 2D nicely set up for us, where it immediately 86

86

applies to anything that is a tile that's being painted onto the tile map. 87

87

And you can see it set it up as a grid. 88

88

So you might have got to that point and said, yes i'm done this is amazing. 89

89

One thing that you'll find is that, if I scroll in all the way here there's 90

90

a miniscule, tiny, tiny, tiny, tiny, tiny, can you see that in there? 91

91

Wonder hoe far it's gonna let me go. 92

92

Between this collision on the right and that collision on the left, 93

93

there's just a tiny fraction different. 94

94

Because we cannot get them exactly exactly the same, and that means that 95

95

sometimes your player could clip into that and touch that collision. 96

96

It also looks a little bit messier to have all of these boxes with all this collision 97

97

and all of this information on here, so we can add to this something really cool, 98

98

which is a composite collider 2D. 99

99

By adding that and then going to our tile map collider 2D and saying, 100

100

used by composite. 101

101

It will apply one macro 102

102

collision around the entirety by joining together those individual collision boxes. 103

103

So you can see, it's a little bit hard to see on here, but if you have a look there, 104

104

you can see the green outline goes the whole way around the outside there. 105

105

If I was to turn that off in terms of the use with collision, 106

106

use by composite, sorry. 107

107

Turn it off, turn it back on. 108

108

It's basically joining them all together. 109

109

When we added that, it also added a rigidbody 2D, that's a requirement. 110

110

And we are going to change the rigidbody 2D to static. 111

111

We don't need it to move, we don't need it to be bouncing around in the world, 112

112

it is just gonna be a static rigidbody 2D, so we have the composite collider, 113

113

we have our tile map collider that is used by composite and 114

114

we have our rigidbody 2D all work in harmony there. 115

115

The last step is to grab our player, 116

116

this is actually the second last step, grab our player, 117

117

throw him up in the world, drop it down and boink not too bad at all. 118

118

I say it's the second last step because when we start to move around our character 119

119

we'll see something pretty interesting happening as we bump into things, 120

120

our character is potentially going to rotate. 121

121

So when we click on the player, jump over to the rigidbody 2D, find the constraints. 122

122

And freeze the rotation on the Z Axis. 123

123

Z or Z axis so 124

124

that our play is not accidentally rotating around as their moving. 125

125

And as a last bit of finesse, if we had a tile that wasn't exactly filling out 126

126

the tile space, maybe it had a little bit of a dip in it, or an edge or 127

127

a slight ramp, then what we can do is to go over into our sprite sheet. 128

128

Couple of things we can do in here. 129

129

If we click on our sprite sheet, go to the sprite editor, we have the ability to come 130

130

into the sprite editor and then edit the physics shape. 131

131

And you'll see that we have these white squares around the outside, and 132

132

if I move this, then the actually physics outline is going to move for that tile. 133

133

So I'll just do something a little bit crazy like that. 134

134

And then apply this. 135

135

Jump back into my scene. 136

136

So that was applied for the corner pieces. 137

137

Click on, it takes sometimes a little bit of time to update this and 138

138

to see what's going on. 139

139

I'll turn off our composite for the moment. 140

140

So we can see that nice and clearly, use by composite. 141

141

There we go. So 142

142

you can see that's updated this physics shape on here 143

143

to something not very elegant or very pretty. 144

144

But that is how we could manipulate the individual shape of 145

145

our collision on individual tiles. 146

146

There's another thing we can do with the tiles. 147

147

If you go to your tile assets themselves, so 148

148

find something that is a .asset file, that is a tile asset, and 149

149

I'll find that same piece in there, which is this Rock_0. 150

150

You can see under here there's Collider Type Sprite, Grid and None. 151

151

If I change this to grid, then it should say, 152

152

instead of doing that funky collision physics outline I just created, 153

153

it should apply just straight up grid outline on that, which it has done. 154

154

And then let's check that if we use Bicomposite 155

155

then it stitches it all together nice and neatly as it did before. 156

156

Okay, so I'll go back and just undo the mess that I created on this tile here, 157

157

that was the illustrative purposes, you don't need to go and mess up your 158

158

collision like that, your physics shaped like that, is drag it back up to where it 159

159

was, drag up there, right that should be nice and neat, reapply that. 160

160

Good to go. 161

161

So we've got our physics set up, couple of different options there. 162

162

Our player, let's apply that back to to the prefab, get into that habit now. 163

163

Click play, 164

164

see what happens when we drop the player down to the world, clunk, perfect. 165

165

We've got our player ready to go and ready to moved around in our world. 166

166

Great stuff in this lecture and I'll see you in the next video.

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