Object that goes right through wall...

I’m working on a retro FPS game, and have stumbled across a small problem. My player can move and look around and shoot, but if you go towards a wall, the gun goes through and you can’t see it anymore. I have included two screenshots: one that is fine, and another that shows the gun going through the wall. Is there a way I can make the gun be shown in front of all the other objects, even if it isn’t really?

Normal:


Through the Wall:


Thanks.

I believe you could adjust the Z-index with a high value (i.e. 10000) in the material settings. You could also form a collision mesh around the gun to ensure that it doesn’t go through walls. You could also play an animation when you get close to a wall (i.e. put it down below the camera view).

Thanks a lot Solarlune! This is really helpful, and I’ll try this out when I get a chance. I can’t right now,because I’m watching the Walking Dead :slight_smile: .

Well,… I changed the gun’s Z-buffer in the material options, and it doesn’t really work. Well, it kinda does. If I am not looking through the camera, it stays in front of everything else. However, when I’m looking through the camera, it still goes through the wall. I have included a picture of the gun working when I’m not using the camera. Is there something I need to change with the camera?


Thanks.

A pretty standard trick is to scale the gun down such that all of it fits inside the player physics bounds, and then move it in close to the camera so it appears to be larger than it is. Alternately you could put the gun in an overlay scene and use message sensors and actuators to make the animations match up across scenes (theoretically you’ll be using an overlay for the HUD anyways)

For more realism, you could animate the gun moving out of the way when it collides with an object (in real life there are specially designed rifles for fighting indoors because normally they are too long and would bang into walls and get snagged on doorframes… that’s why submachine guns and bullpup rifles exist, for the most part) being required to use smaller guns in smaller spaces could be an interesting mechanic in-game.