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.
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 pairs(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