Raycast collisions with character

Hello, my problem is the following: I use raycast for a grab script, object collisions are managed by this one. My problem is that my character is detected by object collisions when it is very close. However I made this line:
local _, part, n = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent, selObj, p.Character, workspace.TargetFilter})

I think I have an idea of ​​the problem, it is that the rays detect everything except objects in CanQuery false, but I am not sure and I have no solutions… Thanks to those who will help me!

(It’s normal for the object to change size, it’s the mechanics of my game)

FindPartOnRay is deprecated, which means it’s no longer supported, you should use workspace:Raycast instead. Any physical object with the CanQuery property set to false will be ignored.
You pass in an origin, then a direction, and then a RaycastParams object, which can be created using RaycastParams.new().
Any objects within the FilterDescendantsInstances property of the RaycastParams object will be ignored by default, so you can just put the local player’s character into that table. Either that, or you can loop through the descendants of the local player’s character and set CanQuery to false on each BasePart.

Here’s an example:

local params = RaycastParams.new()
params.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
local raycastResult = workspace:Raycast(origin, direction, params)
if (raycastResult) then
     print("Hit something")
end
1 Like

Thank you very much, I didn’t know this was obsolete, after a few tries, it worked, thank you! I still set the character to canquery false because it didn’t work without

On the other hand, each time the position of the object is changed, the character finds its collisions CanCollide to lose them immediately so as not to have problems with collisions with the walls.

Before calculation :

for i, v in pairs(p.Character:GetDescendants()) do
if v:IsA(“BasePart”) then
v.CanCollide = false
v.CanQuery = false
end
end

After :

for i, v in pairs(p.Character:GetDescendants()) do
if v:IsA(“BasePart”) then
v.CanQuery = true

  		if v.Name == "UpperTorso" or v.Name == "LowerTorso" then
  			v.CanCollide = true
  		end
  	end
  end

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