Hello. I want to fix viewmodel clipping in roblox. I’ve seen other games do it so I thought it would be nice to add it to my own. I managed to do it BUT it’s really glitchy. Is there a way to fix it? I will link a video down below and my code too :
robloxapp-20240724-1814263.wmv (3.8 MB)
Here’s my code : `local rayOrigin = Gun.ShootPoint.WorldPosition
local rayDirection = Vector3.new(0, 0, Gun.Size.Z * 2).Unit
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {Gun, plr.Character, Gun.Parent}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = workspace:Raycast(rayOrigin, rayDirection, rayParams)
if ray then
if ray.Instance then
print(ray.Instance.Name)
local distance = ray.Distance
CollisionPos = CollisionPos:Lerp(CFrame.new(0, 0, Gun.Size.Z * 2), 0.1 * DT * 60)
else
CollisionPos = CollisionPos:Lerp(CFrame.new(0, 0, 0), 0.05 * DT * 60)
end
else
CollisionPos = CollisionPos:Lerp(CFrame.new(0, 0, 0), 0.05 * DT * 60)
end`
Hope someone helps