Prevent Weapon From Going Into Surrounding Graphics

If any of you have played any of the Call Of Duties - you will notice that when you walk up to a wall (for example) - your weapon doesn't go into the wall, it remains completely visible. Where as my weapon in Unity, when I walk up to a wall or something else, my weapon goes into the graphics.

How do they prevent that from happening? Any ideas would be fantastic.

Thanks All!

Put a collider on your character that is big enough for your gun too, so it is one big collider including the player and the gun

Make the weapon a GUI. That should solve all your problems. Add appropriate animations for fire and reload by removing GUI and adding it back up. Although you can also add the weapon some collider.

puttin a coliider on the gun DOESNT WORK! if it does for you please explain how , in detail. the layer/cam method works but i cannot use a zoom/aim function for my FPS cuz itl show two guns on the screen!. someone pls help isomet ime now
ve been tryin to fix this for quite a while now

  1. Put your gun in new layer (eg. “Weapon”).
  2. Duplicate your main camera.
  3. In it’s Culling Mask, check “Nothing”, and then check your weapon layer. (now the camera should show your weapon only).
  4. Set your modified camera’s Depth to 1.
  5. Enjoy!

Clearly you played to many crappy Call of Duty games, in CoD2, CoD1, and UO, they all go through the walls... The only decent one after this was MW1... All the other blow...

BESIDES THE POINT, you put a collider on the gun, I prefer capsule or cylinder like.

But that should work =).