Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In a game, we use colliders for two main purposes. The first is to limit what a player can and can't get to. We can keep a player from thankfully passing through walls this way. And the second then, is we'll use our colliders as triggers. If we enter a collider or collide with it, something will happen. We'll use the colliders as triggers to help with the animation in the building, but first we need to get in our fixed colliders. The colliders that are put in place, so we can't simply walk through any surface, but are instead bounded along a player path.
A player path in a game then is the area we want our player to go. Even in an open world, where the player in theory can wander anywhere in here in the gallery, we need to make sure our player is simply can't get through some things and are eventually herded by the colliders and what they open up out to the exit or so they'd hope. And in the mean time, hopefully, there's some fun game play as well. What I'll do for my colliders is try to use a box collider in as many places a possible, optimizing the colliders as frequently as I can.
A box collider is one of the cheapest, and a mesh collider is the most expensive. And most of the objects in here will work nicely with a box collider. And we simply can't tell that we're hitting a box instead of the actual object. For my bridge, I'll start out by selecting the middle railing section. And I'll choose Component>Physics>Box Collider. Now, I can scale out this box collider by increasing the z size or take the value from the bridge collider I added earlier. I'll pick the bridge collider and there's a z of 1,217.
I'll copy that number. And come back in here and paste that in. Now I've got a box collider that spans that entire bridge railing. The two side sections of railing are there only as mesh renderers. They're there to look nice, really, but not to keep the player in. I'll copy this component as well. Dropping down next to the gear and choosing Copy Component and then picking the other railing side and pasting in. This will work in many places. Although it depends how an object was cloned around.
Now I have a collider on the bridge and so I can't fall through it. And I can't pass through the railings. Well, there's that collider. And I'm ready to look at the other pieces. I'll pick the next railing section over and put a box collider on it. For this long railing section, I'll pick that middle section and add a box collider and then scale it out. I'll put in a size as a guess to start. I'll try 920 and see how it looks. Then I'll move this collider. It doesn't have to necessarily be centered on that object.
I'll pull it back here And there's a rough fit, it looks pretty good. What I'll go in and do, is check and make sure that the collider has a small enough gap to the next railing that when I get a collider over here, the player can't really squeeze through, and it looks pretty good. I'll get a box collider on this cruciform column as well. I'll choose Component>Physics>Box Collider, and I'll repeat with the next one over. Again, Component>Physics>Box Collider, and finally this last column.
If it's difficult to see in here, you can always turn off the light. Toggling off and on the built in lighting and seeing things in a flat shape. I've put on box colliders on the column and railing sections. And now I need one on this last screen here, because it does sort of pop into that space. I'll choose Component>Physics>Box Collider. And later, I'll be adding a box collider that takes up most of this windowed wall inside. This way, the player can hit the column here, and probably catch that corner if they really decide to bump around into things.
But it won't feel like they're being arbitrarily kept out of this area. I've got box colliders on the bridge and along here on the floor of the bridge, the podium, and most of the railings in this section. I'm going to put in another game object as a marker for my spawn point. And then I'll get in and test out this game. I'll choose Game Object>Create Empty. Add a label in by clicking on the cube and giving it a color, and I'll name this spawnmarker. Now, I'll borrow the coordinates from the player controller, rolling up the master building group and choosing the first person.
And there's it's position. Negative 74, five, and negative 12. I'll pick my spawn marker and put those coordinates in. Negative 74, five, and negative 12. And now I've got this spawn marker position back here with the first person controller. So I can move that first person around and know where to put it back to. I'll pick my first person controller. It may take some navigation here in the hierarchy and I'll pull it over onto that bridge and give this a quick test.
I'll start out on the balcony and I'll hit Play and see how it looks. Here in my game, with all the terrain hidden, I'm back to floating in the blue sky. But, as I come forward here, I hit that railing. I simply can't walk right off it, and I can bang into the pole, and into the next railing. I actually have to navigate around and across the bridge and I can't jump off the bridge anymore. My colliders are working. Over here, forgot to put the collider on and I'm falling off the world. So you can see in here, where thinking through the colliders very carefully is important.
We want to avoid places where the player dies inadvertently by falling off the world. Gravity exists inherently in Unity. And your player controler has mass so if you fall off the world because somebody forgot a collider, you're out of the game. So, put the colliders in. I'll go through and finish out all the box colliders on this, scaling and sizing them out and adding them in anywhere I need to hem in that player. Then we'll get going on putting the triggers in. And getting our game more playable, not just a place to run around.
Get unlimited access to all courses for just $25/month.Become a member
107 Video lessons · 33904 Viewers
94 Video lessons · 23678 Viewers
100 Video lessons · 4085 Viewers
78 Video lessons · 10277 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.