Prevent gun clipping through walls

The JU TPS has a system that prevents gun clipping through walls, and it works very simply

Prevent Gun Clipping Script

This script uses a additional Wielding Position ID from the Item Aim Rotation Center to adjust the weapon's position to avoid clipping through walls. This script must be added to each weapon individually.

ParametersDescription

To Up Direction Wielding ID

Basically it is the ID in the Item Aim Rotation Center that prevents the gun clipping through walls

Ray Distance

Distance from Item Aim Rotation Center to the tip of the gun barrel

Block Gun Fire On Prevent Clipping

Makes it impossible for the character to shoot while preventing the weapon from clipping through walls

Walls Layers

Layers that the Raycast will detect walls

On Prevent

Unity Event that is called when a wall is detected

On Stop Prevent

Unity Event that is called when a wall stops being detected

Creating a Prevent Gun Clipping Wielding Position Reference

The image below shows what a Wielding Position Reference should look like to prevent gun clipping.

You can create adjustments that prevent gun clipping individually per weapon, just create new Wielding Position References and adjust the position, that should be close to the body and pointing in a direction other than forward, and then write the Switch ID in the first parameter of the Prevent Gun Clipping Script

Last updated