How would you go about preventing gun clipping in an FPS?

Hi All,

As the title says, i’m wondering how i would go about preventing my gun from clipping through my environment meshes. I have a few ideas, but i’m curious as to what is regarded as the ‘best’ solution.

First of all - scale down the hands mesh. Simple, but i’m worried it’d make the animations look wonky and complicate future animations

Secondly - some sort of system that moves the gun mesh back when you get close to a wall, driven by a raytrace and a spring arm component

Finally - render the gun over top of the environment

What would be the best way to approach this?

Thanks for your input.

Might be a silly question, but did you notice the default 3pc has collision meshes in the ends of the gun barrels?

Hello Lukas Kelemen,

I don’t think there’s a best solution, it would depend on a lot of factors.
If you want to go for performance the first option would be the most appropriate one, bear in mind though, for a good result you should scale the hands with the distance to the camera (1 / distance). This solution might break easily though if the player get’s a different view on their hands.
The second option would give a bit more feedback to the player and may be regarded the best visual one, because you’re communicating to the player that they’re close enough to the wall that the character cannot hold the object between them and the collider the same way they’d normally do.
The third one would be the least amount of work, but at the cost of more render overhead.

Hope that helps. If this answer was too confusing or not specific enough, just let me know.