Need help smoothing my Anti Clipping

I need help making my anti clipping for my gun system smooth as how it is now is not good enough.

  1. What is the issue? Include screenshots / videos if possible!

  1. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I have tried many I even tried rewriting my whole Bind to render step code to hopefully fix it, I’ve hunted the forums but there doesn’t seem to be a topic that covers this issue

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Just in case you want the code in a non Screenshot form:

--// Anti Clipping 
		local Params = RaycastParams.new()
		Params.FilterType = Enum.RaycastFilterType.Exclude
		Params.FilterDescendantsInstances = {Char, Viewmodel}
		
		local ray = workspace:Raycast(workspace.CurrentCamera.CFrame.Position, workspace.CurrentCamera.CFrame.LookVector * 5, Params)
	
		if ray then
			viewmodelCF *= viewmodelCF:Lerp(CFrame.new(-0.3, 0, 0))
		end
		
		--// Apply CFrame to Viewmodel
		local MainPivot = Gunmodel:FindFirstChild("Core").Handle or Gunmodel.PrimaryPart
		Viewmodel:PivotTo(workspace.CurrentCamera.CFrame * viewmodelCF * BobCF * JumpCF) --// Add AimCF & CrouchCF when I implement it 
		MainPivot.CFrame *= CFrame.Angles(updateSwaySpring.Y, updateSwaySpring.X, 0)

try getting the distance from the ray origin to the ray hit position, then remove that value from the length of your ray and move the viewmodel back by the resulting number.

something like this is what I’m thinking

local rayLength = 5
local offset = CFrame.identity
local rayOrigin = camera.CFrame.Position

local ray = --raycast here
if ray then
  local distance = (rayOrigin - ray.Position).Magnitude
  offset = CFrame.new(0, 0, rayLength - distance)
end

viewmodel:PivotTo(camera.CFrame * offset)

I don’t know how well or if this will work but the thought is to move the viewmodel backwards based on how close you are to the wall

1 Like

Thank you so much i’ve been working on smoothing it out for about 40 mins now :sob:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.