How to make bullet to collide with wall when you are close to it?

Hi
My question is that I have created a weapon that fires a bullet.The problem is the bullet collide with the wall when you are at a proper distance but when you get close to the wall the bullet penetrates the wall and keep moving until it collides when another wall.

Please let me know the solution to this problem.

Thanks in advance

I put a collision on the gun. You can set it so if it hits something you can play a arms animation to move out of the way. The cool thing about it is you can hit things with physics with your gun lol

Thanks
But i don’t understand what u r trying to say.I have collision enabled on gun and on bullet but the bullet won’t collide when u r close to the wall.And how to set physics to gun.If i do that my gun will fall down because of the gravity.