How Can We Help?

How do I prevent my gun from going through walls?

Depending on how you created your character and the Body Shapes you use, you may find your character’s body, weapons, or gear intrude on walls or other objects.

AAA games handled this in a couple of ways (sometimes mixing the approaches).

 

Multiple Cameras

One thing most games do is allow for a second camera. This second camera culls out most of the scene and renders only the character and the weapon. With this approach, the character parts still intrude, but the re-drawing makes it look like they don’t.

This is especially effective in first person games.

You can do this in Unity by putting your character on a separate layer. Then, have a second camera that has the same exact position and rotation as the first camera.

This second camera would not clear the buffer before drawing and then culls everything except the character’s layer.

 

Wall Buffers

Another technique is to use wall buffers. Basically you’re inflating the colliders around your walls so that characters can’t get directly up against the actual meshes.

With this approach, using a different camera field-of-view can still make it look like you’re close to the wall.

Witcher 3 and other games use this approach too.

If you’re in Witcher 3, run up to a wall and then look down. Your character’s feet are a good foot or two from the wall even though it looks like your face is up against it.

 

Body Shapes

With the Actor Controller, the other option is to increase the character’s body shape radius.

I’m not a huge fan of this as that means the character can never get close to any object, but it is an option.

 

The best solution is probably a mix of all three. You’ll have to play with them to see what works best for your game.

Page Contents