How to fix FPS Gun Clipping Glitch [Unity Tutorial]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys mike here from comp3 interactive welcome back to the channel i hope you all had a lovely christmas hope you got everything that you ever wanted but now that the holiday season's over it's back to business and i'm back making tutorials and after my little break what i'm gonna do i'm just gonna come back in with a relatively simple and straightforward tutorial but something that a lot of people seem to not know how to do and that is gun clipping and by gun clipping or weapon clipping what i mean is this so as you can see i've got a very basic first person controller we have a weapon attached to our camera which follows us around and we have this huge wall now when i get too close to the wall the weapon clips through the wall and obviously we don't want that because that just looks stupid and that is an extremely simple fix and all we need to do there's no calling involved we just need a second camera but before we get into it i just want to thank gigatank 3000 for sponsoring this video i've got his links in the description below go check him out on twitter go check out his website keep on track of what he's up to and i'd also like to thank everybody supporting me over on patreon we've got steve uk and brandon zill you guys are fantastic love you so let's get into it how do we go about doing this well i'll just give you a quick walkthrough of what i've got so far we have our environment set up our wall a floor and then we have our player now this is a pretty standard setup for a first person game we have a player which has a capsule collider and a rigid body and a fps controller attached to it now if you want a brief overview of that fps controller it is a very simple one but if you want to have a look at what's inside though drop a comment below and i'll do a quick tutorial on making a very basic fps controller but now inside of our player object we have our main camera now our fps controller grabs all of this and we start rotating the camera with our mouse movements pretty simple stuff and then finally we have this org weapon that's underneath the main camera in the hierarchy again pretty simple stuff but because the org is a 3d object when it gets too close to another object because this doesn't have a collider attached to it it's going to clip through so we could either put a collider on the weapon but then a player wouldn't be able to get as close as we want them to to the wall so instead what we can do we can use something called camera stacking and what that's going to do we're going to create a new camera that's sole purpose is to render a weapon then we're going to stack that camera on top of our main camera as an overlay and then that weapon is always going to be rendered on top of everything else in our game and again really really simple to do so what i'm going to do again as a child of my main camera i'm going to right click and i'm going to create a new camera and then with this new camera i'm going to change a couple of the settings and i'm also going to remove this audio listener because we only need one audio listener in our scene at any given time so what settings do we need to change we'll start from the top the render type instead of being a base camera we want to click that and change it to an overlay camera and you'll see some changes automatically in your scene view next we want to change the clipping planes near to be as low as possible 0.01 that way we don't get part of our gun being clipped off when it's too close to the camera next we don't want a camera rendering any shadows we want to make this as performance as possible and we'll get rid of occlusion culling as well so now currently we have two cameras that are rendering pretty much the same thing so we want to tell our second camera uh weapon renderer we'll rename that renderer we want to tell that camera that we only want to render the weapon and we can do that by setting the culling mask but the first thing we've got to do we've got to set up a layer for our weapon so if we select our org go over into our inspector select the layer and instead of default we're going to add a new layer and we'll call that weapon now set a org to be weapon and just remember if you've got multiple weapons in your game you're going to have to have each one of those weapons as a weapon layer next we'll click a weapon renderer and down here where we've got calling mask we'll change it from everything to nothing quickly and as you can see in here we are currently rendering nothing apart from the box and then we'll change that back to weapon so now our weapon renderer should only be rendering any objects that have the that are on the layer weapon and just to make sure that we're not rendering that weapon twice we'll select our main camera go to the culling mask and this time we'll just uncheck weapon so now you can see if i select the main camera we don't have a weapon rendering but we do have the ground rendering if i select my weapon renderer we don't have the ground but we have the weapon now the final thing that we need to do we select our main camera come right down to the bottom where we've got this stack option and it should be empty for you now if we click the little add to list plus icon it'll detect every camera in your scene and we've called as weapon renderer so we'll click that and now what unity is going to do that's going to merge the outputs from both of those cameras into a single image so now that should be it that should be our weapon running perfectly fine if we play the same game again we've made no changes apart from our camera if we walk over to our wall we can see we no longer clip through perfect that is exactly what we were looking for and as you can see it's really simple to do not much needed just a few things to remember like i said when you're creating a new weapon just make sure that any weapons that you create are on the weapon layer and just to make it perform and make sure that you don't render the weapons on the main camera only on the weapon renderer so it has been a short video and i intentionally wanted this to be short video because a lot of people seem to have problems with this and i just wanted to emphasize how quick it is to fix this so thanks for watching guys i'll see you again next week thanks for watching guys don't forget to like comment and subscribe and follow us on facebook and instagram for more bites as unity hints and tips you
Info
Channel: Comp-3 Interactive
Views: 18,700
Rating: undefined out of 5
Keywords: comp3, comp3interactive, unity, unity5, unity3d, unity2d, tutorial, game, development, dev, introduction, program, programming, code, coding, csharp, c sharp, c#, games, 3d, 2d, artist, programmer, extension, easy, beginner, advanced, professional, multiplayer, how to make a game, how to make games, game development, how to use unity, brackeys, comp-3 interactive, unity 2d, unity 3d, how to make, how to do, game developer, game dev, make money with games, first person, fps, weapon clipping, gun clipping
Id: wH4IyFXrWQw
Channel Id: undefined
Length: 6min 49sec (409 seconds)
Published: Fri Jan 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.