I’m making a system that allows us to hold objects and I use raytracing to detect walls and prevent object to clip through wall. But when I look at a certain angle to wall, some parts of the object clip through wall. How can I prevent this from happening?
local function mesafe(b)
local distance = mouse.Hit.Position - character.Head.Position
part.Position = character.Head.Position + distance.Unit * b
end
local function render()
local x, y, z = mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z
local raycastparams = RaycastParams.new()
raycastparams.FilterDescendantsInstances = {character, part}
raycastparams.FilterType = Enum.RaycastFilterType.Exclude
local raycastresults = workspace:Raycast(character.Head.Position, (mouse.Hit.Position - character.Head.Position) * 300, raycastparams)
local Magnitude = (character.Head.Position - raycastresults.Position).magnitude
--print(Magnitude)
if raycastresults and Magnitude < 10 and Magnitude > 1 then
b = raycastresults.Distance
mesafe(b)
elseif Magnitude > 10 then
b = 10
mesafe(b)
end
end