Prevent gun clipping through walls
Last updated
Last updated
The JU TPS has a system that prevents gun clipping through walls, and it works very simply
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.
To Up Direction Wielding ID
Ray Distance
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
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
Basically it is the ID in theCenter that prevents the gun clipping through walls
Distance from to the tip of the gun barrel