How to prevent weapons from penetrating the wall?

I’m creating an FPS and the problem I’m currently having is that the weapon in the hands of my character are penetrating the wall if you get close. I’d like either the hands to back off so that you just see the wall if you come any closer (ideally) or simply to not allow the character to go closer than the end of the gun (I guess this would be easier and it should be enough for a temporary fix). How may I achieve either?

As for the latter, I tried resizing the capsulecomponent of my character but it created a lot problems cause:
a) not all the weapons are the same length
b) I couldn’t figure out how to make the capsule fit tightly and as a consequence you couldn’t walk through narrow doorways

What is the easiest solution to the penetration problem? I thought about attaching a volume to the end of each weapon in their blueprints and then somehow checking if it’s colliding with a wall and if so, blocking the W key. Anything better?

I’m assuming the weapon is socketed to the hand:

  1. If you get the character’s direction and invert it(rotate by 180), use that to rotate the weapon, but if it’s socketed that’s no good, 2)so you can make a little forearm moving up animation, do an animation blend, and set it’s parameter to how close the player is to the wall, that’s going to do a realistic job, but I don’t think it’s worth the effort, especially if you’re doing mmorpg, you don’t want to run that code on all characters as animations will be replicated.

Edit: Oh you will also want to add that animation to your locomotion I think, for it not to interrupt other animations, I’m not on animating stage in my game right now so not completely sure.

I remember this already answered o.o

But ok. The answer to this is:

Normaly you would have a seperated layer for the rendering. The Source Engine for example renders the First Person weapons on a seperated layer. So the are rendered in front of everything. The Unreal Engine doesn’t have something like this.

So what can you do? As you already said, you have 2 ways:

Either create an animation for the arms that pull up the weapon like in real life, so that it’s 90° rotated if you come near the wall. You can do this by Line Tracing in forward direction and just calling the animation if you hit a wall or something.

Or you could try faking this a bit. As you mentioned, resizing the Player Capsule would be an option, but what about resizing the weapons? Only the player sees them and he won’t see that they are tiny, as long as you position them in near enough so that they seem big. With this you could make them small enough to fit into the normal capsule.

Yes true, also if you don’t want to resize the weapon and it’s a single player game, you can put a little collision sphere on the tip of the let’s say polearm or staff, and make it’s collision preset block all.

I see. I tried your tip posted below (adding collision sphere), but regretfully adding it and setting to BlockAll blocks nothing and the weapon still penetrates the wall :frowning:

Hello!
I’m not sure if you fixed the issue but this is how I FIXED mine!

1 Line trace from player to some distance, You can do this by line trace by channel . Connect Start to get actor world location from Get player character. The end location in my case is Get player character → Get forward vector → Vector * Float - > Add that to Get actor world location. Float was somewhere around 160 for me, it’s your preference.

  1. From the return value of Line trace by channel set a Boolean variable as shown in the picture

  2. So have animation like player bending the elbow up whenever he goes against a wall tested against the Boolean value you set at line trace by channel. Hope that helped cheers! XD