How to stop gun clipping

im making a fps framework but the viewmodel clips through walls because i turn off collisions. how do i render the gun over the game so this doesn’t happen?

4 Likes

I used viewport frames to do this.

The only problem is that viewport frames have different lighting, but other than that it works fine.

Here is a video demonstrating this:

20 Likes

my engine relys on the viewmodel being in the camera. what should i do to get it to show on the viewport frame too? should i duplicate it?

The only way to prevent clipping is by using a viewport frame. If you have to use the camera you have to deal with clipping.

how did you get the framework to work with viewport frames? could you share some code im trying to get it to work right now

I just keep a reference to the view model in my main local script. I have a bunch of modules, and a main local script that connects everything together. The main local script has the reference to the viewmodel, from there I just parent to the camera if I don’t care about collisions, if not I parent to a viewport frame. It isn’t dependent of the parent at all.

i was able to get viewport frames working! its not the best way i think but the duplication method works!

an easier way could be just shrinking the viewmodel entirely. (it isnt as effective but still works)

You can try to cast a ray, that ignores the viewmodel but only collides with the terrain, from the camera to the barrel of the gun.

When the ray hits, it means that the barrel is clipping and you can play an animation to show the gun cannot be fired.

I have use a this tactic to my fps games.
When the player is near a wall (raycast) you switch the view model to a viewport
When they are not switch back the parent to the camera.

1 Like

doom eternal/2016 (i think its also in 2016 but i cant really play it because my pc isnt good enough) does this but a bit better where it turns the gun sideways based on how far the camera is to the wall

I realize this thread is pretty much dead by now, but how did you keep all the parts together? Did you have to manually cframe all of them (since welds and motor6D’s don’t hold in viewport frames)?

Thanks,
Dynamic

No, I had them together via Motor6Ds. They hold together if you put a WorldModel inside of a ViewportFrame and you put the viewmodel inside of the WorldModel.

2 Likes

my system just uses cframe of the primary part, but once I place the view model into the viewport it freezes in place…

i know this topic been solved but to fix clipping and make it work with lighting is just making the viewmodel small but not too small where it would completely clip into the camera

wont fix all the clipping if your using a long gun/item but it would fix most clipping

Lie’s You Can Detect The walls using the client script