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.
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:
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
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.
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
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)
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)