Gun going through wall when turning around

Hi guys, I’m working on a first person action game right now and when I equip a gun to my character and go next to a wall, my gun overlaps into the wall (my character is not going through the wall). I’ve realized that the problem is the capsule component of the character is not wide enough and doesn’t encapsulate the gun. Is there a good way of fixing this without just expanding the width of the capsule since I could have different guns that are different lengths? I’ve tried expanding the capsule width, and it works but the problem now is that now it seems like an object is far away from you even though you’re supposedly suppose to be next to it (since the length of the gun extrudes farther out). This is the problem I have but in Unity:

Thanks!

You could try tracing a line out from the character for the length of each gun, and if the character is too close, make the character point the gun into the air.

Or (And I don’t know how to do this in UE4) you could render the hud and player arms separately on top of the normal render, so even if the gun “should” be going through the wall, the player can still see it fine.

In first person games a common trick is to draw the gun after the environment, this way you wont have that issue. Check if you can change the depth priority of the weapon mesh when in first person view using ESceneDepthPriorityGroup ViewOwnerDepthPriorityGroup, change it to foreground.

Another way you can do it is simply add a collision box to your weapon, and if the weapon isn’t pointing to the air, check for collision agains’t meshes & brushes, if it collides > point it to the air.

DepthPriorityGroups have been removed in UE4. This is causing me a big headache as well.

anyone know how to achieve this? In every FPS engine there is an option to render hands/mesh after everything. You can manipulate matrixes as well to achieve this.

Not sure whether it was added since 2014 but looking at UPrimitiveComponent there’s a member DepthPriorityGroup and ViewOwnerDepthPriorityGroup (just like in UDK). I’m not entirely certain they still work but it’s still used in quite a lot of places within the engine so I would assume so. You can just try it I guess.

You could also check out how it’s done in the new Unreal Tournament.