Weapon clipping fix (Using new model "Scale")

Before:
(I didn’t even go to the wall completely)

After:

I made a script that will prevent weapons from clipping into walls. Simply, it just reduces weapons with the help of a new Scale function for models, and retains the appearance of CFrame animations of weapons such as walking animation, sway, etc.
ex

local function multy(cframe:CFrame,n:number):CFrame
	return CFrame.new(cframe.Position*n,cframe.LookVector*(n*10))
end
local run=game:GetService'RunService'


local scalefactor=.25 --default is 1

local weaponmodel:Model=workspace.weaponViewmodel--example

weaponmodel:ScaleTo(scalefactor)



local recoilOffset=CFrame.new()
local aimOffset=CFrame.new()
local customviewmodel=CFrame.new()

run.RenderStepped:Connect(function(dt)
	weaponmodel:PivotTo(-- or weaponmodel.PrimaryPart.CFrame=
		cam.CFrame
			*multy(
				-------here are all the cframe functions
				recoilOffset -- example
				*aimOffset -- example
				*customviewmodel -- example
				...
				,scalefactor*1.25
			)
	)
end)

My weapon model:
deaglemodel

You may have a problem with hand materials after that, they will be enlarged and look pixelated, so you can use

for _,part:MeshPart in weaponmodel:GetChildren()do
	if part:IsA'BasePart'then
		if part.Name:lower():match'arm'then--"Left Arm" -> "left arm" -- matches 'arm'
			for _,side in{'Front','Back','Left','Right'}do
				local tex=Instance.new('Texture',part)
				tex.Face=side
				tex.Texture='rbxassetid://12674931068'--skin texture
				local size=.5
				tex.StudsPerTileU=size
				tex.StudsPerTileV=size
			end
		end
	end
end

Preview:
imgur video

Game in video: Standblox

10 Likes

That’s pretty cool but I don’t really like the method your using. Because you know

V I E W P O R T . F R A M E S

exist. Well I mean maybe I am wrong because I never made such thing but still very cool
image

8 Likes

If viewports will be

  • With a small fps the viewport will have almost two times less fps

  • There will be no visible shadows and lighting on the weapon

  • You need to create a WorldModel in the viewport, which also lowers fps, but not only in the viewport

6 Likes

I can confirm that this method works good enough when I tried something similar. However, it did not work in a public game because Scale was not released in public yet. This is basically just using forced perspective to make it look bigger, while actually being smaller to reduce clipping.

2 Likes

Noooooooo : (I already wanted to post an update, I thought that the function is included in the place. Well, waiting for the release, although as for me it works properly

1 Like

Additionally, viewport frames have a resolution limit and no anti-aliasing, which results a forced outline. It’s really ugly on large screens

4 Likes

your code needs to increase some readability, please change the code for better readability :wink:

3 Likes

Just letting you know, :GetScale() and :SetScale() will be released tomorrow

4 Likes

And how can I adapt the CFrame to the scale, because for example my GunCF (The position where the gun is) is misaligned when changing the scale of the model.

CFrame.new(0.5, -0.85, -1.15)

local function multy(cframe:CFrame,n:number):CFrame
	return CFrame.new(cframe.Position*n,cframe.LookVector*(n*10))
end

local Scale = 0.25

MainModule.AnimPart.CFrame = MainModule.CurrentCamera.CFrame * multy(MainModule.MainCF, Scale * 1.25)

try

local function multy(cframe:CFrame,n:number):CFrame
	return CFrame.new(cframe.Position*n,cframe.LookVector*(n*10))
end

local Scale = 0.25

MainModule.AnimPart.CFrame = MainModule.CurrentCamera.CFrame * multy(MainModule.MainCF*CFrame.new(0.5, -0.85, -1.15), Scale * 1.25)

The gun is now well positioned but for some reason it is rotated a couple of degrees. Maybe is the Camera CFrame? Idk.

Hello! Your method (almost) works really good for me, but I have an issue, I can’t explain it so here’s a screenshot :

try to multiplying weapon cframe by for example CFrame.new(0.1, 0.1, 0.1) to find right positioning