Collider component in Unity

Transcript

English (Auto-generated)

Hi everyone in this cast, we'll be talking about colliders. Now colliders are invisible shapes on three D. Objects that define collisions. A collider can be added to a game object such as this one. So I already have a collider here but let's delete this so we can add a collider to the Q. Just by going to add component and then searching for collider. So there's six different types of colliders. You have box sphere, capsule, mesh wheel and terrain. And the one we'll be using is box since this is a cube. So I'm going to go ahead there and select box collider. Okay so remember I said that it is an invisible shape on three D. Objects that handles collisions. So let's visualize this collider. And what I'm going to do is in the inspector window where it says um center center X. Is equal to zero. Let's just move this around. So when I move this around here you can see that it is an invisible shape and let's just put it back on the box again and I believe that's zero. There you go. Okay and you can also take a look at this invisible box collider by actually uncheck ng this mesh render component out here which will show us the shape of the box collider on the cube. And here you can see that this is the box collider. Right? So let's uh take market again. There you go. Okay now moving on let's have a look at the default behavior of the three D. Cube in this scene by play pressing on the play button. Now it's not gonna do anything as yet and let's see why. Okay number one is just a floating in the sky or in the air because it doesn't have a rigid body component. So remember both rigid body and colliders are important in game collisions. So let's add this rigid body component. I'm just gonna select rigid body which is for three D. Scene here. And now let's also make sure that it's using gravity. So yes it is. And just to recap we went over rigid body in a previous cast and a rigid body in Unity Treaty is a component which when added to any game object will allow it to react to fundamental physics behavior for example gravity acceleration, mass so on and so forth. Whereas colliders are invisible shapes on three d. objects which can handle collisions. Okay so let's go ahead and now look at the behavior of this cube and there you go. So you see that it just falls. Right so let me go back a bit. It's just going to fall and there it is. So it's just falling to the plane. Right? So we have that collider on there which is basically allowing it to not passed through the plane right now let's disabled, disabled. The box collided and let's see what happens. Right? So what I'm going to do is I'm going to now disable the box collider and you do that by uncheck ng this box collider component. So let's see. Right so now it's not because there's no collider it's not handling collisions. Right? So you can see that upon disabling the box collider the three D. Cube just passes it through this blue plane due to the absence of a collider. And colliders handle collisions between objects. So that is the box collider will decide whether two objects intersect with each other or just simply pass through. Now you can add multiple colliders to a game object which can be of the same type or different types. Right? So for example we can add another box collider on the three D. Cube again. So let me just enable this. You could just add another one. It doesn't matter. Usually you wouldn't need more than one. Right? So if I disable the mesh render let's just see it. Right so out here you can see I have a box collider. Um Let's see we actually don't need to add um the same one. We could add a different collider. Let's see um remove component. And then let's say collider collider capsule collider. Right so now I can you can maybe see the capsule collider. Let me just move it. There you go. So I have a capsule collider and I have this box collider. Right so you can add multiple colliders but you don't need to do that. So I'm just going to disable the capsule collider here. Okay so let's just go over now. The properties of this collider. Right? So number one you have the size, so the size of the box collider indicates the size of the collider along X. Y. And Z. Axis. So we can make this a bit bigger. So let's say two two and two. So now it's scaled up to two on the X. Y. N. C. Axis. And then we have a center here. So the center property. Now center indicates the offset of the collider from the center of a game object. So 000 is placing the collider at the center of the three D. Objects. So if we change it there you go. So now the collider is 111 on the X. Y. And Z. Access. So it's been offset by one unit, it's no longer in the center of the game object. Usually you want the collider at the center. Right, Okay. And then we have out here material so material, this is going to determine the physic material of a collider. So is the collider, plastic, metal, wood, glass and so on and so forth. So this is different from the material which controls the look of an object. This material out here and the collider actually controls the behavior of an object. Now you can also edit the size of the collider by using this tool here where it says edit collider, right? So it opens this up and basically you can just play around with it from here. Right, okay and the last one is trigger. Now the is trigger property is going to convert the collider into a trigger. So it trigger is a non solid volume such as liquid or gas by default. A collider is a solid volume so nothing can pass through a solid volume. You know, just like in real life you can't pass through a solid thing like a table, right? But you can't pass through non solid volumes such as water or gas. Now triggers. I used to create a space which senses and triggers events when objects stay enter or leave the space. Right so for example when might you want to use a trigger um that is trigger property in a game, you might want to maybe open a door, a three D. Object. Right? Only when the player enters the space which is near the door. Right? So that's going to trigger a collision with the three D. Door object and it's going to open the door. Okay so let's take a look at this. So let me go ahead and just save it and let's move on to a different scene here. Right uh Okay there it is. Okay so here let's see please. Okay so right now you can see that my cube is passing through my let's say let's just say it's a pool. Right so it's passing through my pool or this big rectangle three d. Object. Right? So now what's happening out here is that we've got the is trigger property check mark. Right? So that is triggered property like I just said it's going to convert the collider into a trigger and then we actually have to write some C. Sharp code which will say well when you know when a treaty object enters the vicinity of this pool then do something. Right? So when we check mark, this is trigger box and for this large rectangle which is supposedly water, you can see that. Now the cube is just passing. So this collider now has been converted into a cube. Right? And after that when it's check marked in your C. Sharp code you would actually use trigger event methods such as on trigger stay on trigger exit and on trigger enter to basically trigger something. So that's all for colliders.
17 Views 0 Likes 0 Comments

Colliders are invisible shapes on 3D objectgs that handle collisions. Along with RigidBody component these are important in game collisions

Comment
Leave a comment (supports markdown format)