Viewmodel clipping fix || how to make your viewmodel standout

Have you ever came across this issue where the Viewmodel is clipping through walls or floor?

take note this tutorial expect you to know how to make a viewmodel and knew intermediate scripting

which looks like this… BUT there’s a method which takes it to another level

while it doesnt affect the game, if realistic games are implemented, it would/can be unethical as the hands literally clips through objects

But by applying this effect with a little modification to your code, it will eventually turn your game into more realistic feelings

After

This is actually done surprisingly easy!

How?

How is this done

Originally or Rather mostly; how games do it is they insert the Viewmodel as a game object itself, while it could work, since the game recognize the object as a physical BasePart, It’ll have a collision that’s why we see it clipping

some might script it this way:

local cam = workspace.CurrentCamera
local vm = script.Viewmodel:Clone()

local rs = game:GetService("RunService")

rs.RenderStepped:Connect(function()
	vm.Parent = cam
	vm:SetPrimaryPartCFrame(cam.CFrame)
end)

making the object exist in the workspace

but by adding a fake layer through our viewmodel and game object we can optimize it using Viewport Frame

Start by inserting a viewmodel with nothing in it

image

now we need to modify some property here,

First the ScreenGui’s property, turn on IgnoreGuiSet so it doesnt seem to get squish if you have big Viewmodel

Second the Viewport’s size, set it to 1,0,1,0 so it takes up the whole screen

Third now change the viwport’s background color to the map’s ambience because if we keep it as white, you will see a weird outline at your viewmodel; I highly recommend setting it to 95, 95, 95 because it is the default roblox ambience

Fourth let us modify our original code

local cam = workspace.CurrentCamera -- Make a  variable for camera
local vm = script.Ak47:Clone() --  Locate where the viewmodel is

local rs = game:GetService("RunService") -- get RunService

local viewport = script.Parent.Viewmodel.ViewportFrame -- Locate where the ViewportFrame is
viewport.CurrentCamera = cam -- sets the camera reference to the camera

rs.RenderStepped:Connect(function() -- We're using Render stepped so it runs every frame
	vm.Parent = viewport  -- parents the viewmodel to the viewport so the viewport can see it
	vm:SetPrimaryPartCFrame(cam.CFrame) -- always set the precise CFrame of the viewmodel to the camera
end)

and just like that, we made our viewmodel always draw on top

Advantages and Disadvantages

Advantages

  • gives realistic vibes
  • optimize workspace render
  • light precision and more standing out modifications are free to modify with some basic viewport/ui knowledge
  • looks cool
  • viewmodel transparency customization

Disadvantages

  • looks cut out version if not modified consistently - but can be fixed with some creativity
  • light precision because the viewmodel is lighter than the ambience - but can be fixed
Why is this a common Issue in video game developing and why does this work

Because the traditional way to do it is putting the whole Viewmodel object to the same environment as the main game itself therefore the game thinks its a physical objects and therefore will have a reason why it should clip through the wall

This was fixed through making the viewmodel exist outside the main game’s environment and drawing it to the screen instead.

ALL COURTESY GOES TO THESE GUYS

2 Likes

This isn’t used often since it doesnt look good, another method is to make the viewmodel really small and close to the camera

5 Likes

Not a good idea.

2 Likes

HI!!, before you comment your toxic feelings lol, this is a suggestion not a real fix, there’s a several methods out there obviously

But this is how I make my viewmodels mostly

It isn’t toxicity, nobody uses viewports for thier viewmodel due to insane pixelation they cause. You are better off raycasting and offseting your viewmodel

3 Likes

Viewports don’t look good at all. Using them will ruin the experience and immersion.
Do this;

ANOTHER disadvantage is that particles are unable to render in viewport frames.

Hii!! No I dont see them toxics :smile: , its cause some people just randomly post something ashame at comments when they see someone’s wrong, thankd :smile: