Prevent weapon clipping (How does Tunneler do it?)

As just about any gamer knows, most FPS games render the weapon on top of the 3d world directly in front of the player’s screen and this prevents the weapon from clipping into parts. By this I mean if you walk up right against the wall, you should still be able to see your entire weapon as opposed to part of it going through the wall. I’ve come to learn it is fairly difficult to accomplish this in roblox.

Now, I know this CAN be accomplished with viewport frames, but due to their lack of compatibility with lighting effects, the quality is terrible. Below is a comparison of my FPS weapon in the camera vs in a viewport frame.


In camera


In viewport frame

Notice neon parts don’t glow and particle effects don’t show up. This is a major problem.

I have seen ONE game on roblox that has accomplished this flawlessly, and I was hoping I might get some insight on how they might have done it. Tunneler: TUNNELER [Demo] - Roblox @Homemade_Meal

Below is a screenshot showing the player right up against the wall where the gun would naturally clip without preventative measures.


Tunneler no-clip example.

I know it is hard to tell from the image, but particle effects also work perfectly right up against the wall.

Any tips?

1 Like

There’s a simple-ish way you can achieve this without using ViewportFrames. The technique involves parenting objects to the camera. There’s a good reference you can look into here that goes in-depth on how to achieve this.

If you have any questions about this feel free to ask!

1 Like

The weapon in the first image is parented to the camera. It will still clip unless it is moved into a GUI object. I am interested in reading the post you included but the link is broken it seems.

Oh! I apologize about that, the link should be working now.

Ahh I see it now. Yes I have seen this tutorial before. Unfortunately he doesn’t address weapon clipping in it. However, it is a great tutorial for learning to make an FPS!

Is there any difference when you have CanCollide on for the weapon?
I know small Parts may clip anyway, but what if there was a 1x1x2 stud Part that was CanCollide, Transparent, and Massless welded to the gun?

That would prevent the weapon from clipping, but it would cause a worse problem than just letting the gun clip because you wouldn’t have the ability to get close to the wall at all because the gun would hit the wall and stop you.

Edit: Actually in my scenario, the weapon is cframed to the camera on render-stepped. So it would clip anyway.

Obviously can’t confirm this, but it’s possible the portal gun is actually very small, but extremely close to the camera so it appears to be normal size?

This was a trick people used before viewport frames were a thing to get the same effect. There’s still the possibility for clipping when extremely close and you can’t scale the mesh too small or the near clipping plane Z won’t render your model (as shown in video), but with the right value you get the effect in the OP

It’s worth noting you’d pretty much need to use meshes here to get a scale that’s close enough to your camera not to clip into things.

Oh, and here’s vaguely what my code’s doing:

local duck = game.ReplicatedStorage.Duck
local base = duck.Size

local scale = 0.2 -- set this small
local offset = Vector3.new(2, -0.5, -3)

game:GetService("RunService").RenderStepped:Connect(function(dt)
	duck.Size = base * scale
	duck.CFrame = workspace.CurrentCamera.CFrame * CFrame.new(offset * scale)
end)

duck.Parent = workspace
20 Likes

Ah I see! I hadn’t considered this before and I think it’s pretty likely that you are correct about Tunneler. I think I’ll mess with this a bit. It should be possible to shrink a weapon consisting of parts down enough by using the model resize plugin. A small unnoticeable part could be welded to the player to prevent them from getting close enough to a wall for their weapon to clip.

This should work with enough experimenting.
Thanks!

1 Like