Help with Collision groups and/or getting class types for filtering with raycasting

If you saw my last post, then you already know what I’m attempting to do, but I need to find a way to make an easier and cleaner array for filtering descendants for raycasting parameters.

Code:

local players = game:GetService("Players")
local player = players.LocalPlayer
--///////////////
local char = player.Character or player.CharacterAdded:Wait()
if not char then
	repeat wait() until char
	char = player.Character
end
local hum = char.HumanoidRootPart or char:WaitForChild("HumanoidRootPart")
local torso = char.Torso or char:WaitForChild("Torso")
if not torso then
	repeat wait() until torso
	char = char.Torso
end
local leftArm = char:FindFirstChild("Left Arm") or char:WaitForChild("Left Arm")
if not leftArm then
	repeat wait() until leftArm
	char = char:FindFirstChild("Left Arm")
end
local rightArm = char:FindFirstChild("Right Arm") or char:WaitForChild("Right Arm")
if not rightArm then
	repeat wait() until rightArm
	char = char:FindFirstChild("Right Arm")
end
local head = char:FindFirstChild("Head") or char:WaitForChild("Head")
if not head then
	repeat wait() until head
	char = char:FindFirstChild("Head")
end
--///////////////////////
local rightLeg = char:FindFirstChild("Right Leg") or char:WaitForChild("Right Leg")
local leftLeg = char:FindFirstChild("Left Leg") or char:WaitForChild("Left Leg")
local RS = game:GetService("RunService")
local Workspace = game:GetService("Workspace")









if leftLeg and rightLeg then
	local leftA = Instance.new("Attachment")
	local rightA = Instance.new("Attachment")
	leftA.Visible = true
	rightA.Visible = true
	leftA.Parent = leftLeg
	rightA.Parent = rightLeg
	RS.RenderStepped:Connect(function()
		local rightRayOrigin = rightLeg.Position
		local rightRayDirection = Vector3.new(0, 5, 0)
		local rightRaycastParams = RaycastParams.new()
		rightRaycastParams.FilterDescendantsInstances = {leftLeg, rightLeg, hum, torso, head, leftArm, rightArm}
		rightRaycastParams.FilterType = Enum.RaycastFilterType.Exclude
		local rightRaycastResult = Workspace:Raycast(rightRayOrigin, rightRayDirection, rightRaycastParams)
		print(rightRaycastResult.Instance)
		
		rightA.Position = rightRaycastResult.Normal
	end)
end

so is this all just trying to get the floor material, or something else?
also for FilterDescendantsInstances thing, you can just do player.character, or here, char, and it won’t pick up anything that is under the character.

1 Like

I’m printing the instance for debugging and seeing what it’s actually hitting. It’s trying to project an attachment to the ground so that I can use it for procedural animation.

I tried the player.character, but it gave me the "attempt to index nil with ‘Instance’ at the print line

can you send the full script when you do that?

1 Like
local players = game:GetService("Players")
local player = players.LocalPlayer
--///////////////
local char = player.Character or player.CharacterAdded:Wait()
if not char then
	repeat wait() until char
	char = player.Character
end
local hum = char.HumanoidRootPart or char:WaitForChild("HumanoidRootPart")
local torso = char.Torso or char:WaitForChild("Torso")
if not torso then
	repeat wait() until torso
	char = char.Torso
end
local leftArm = char:FindFirstChild("Left Arm") or char:WaitForChild("Left Arm")
if not leftArm then
	repeat wait() until leftArm
	char = char:FindFirstChild("Left Arm")
end
local rightArm = char:FindFirstChild("Right Arm") or char:WaitForChild("Right Arm")
if not rightArm then
	repeat wait() until rightArm
	char = char:FindFirstChild("Right Arm")
end
local head = char:FindFirstChild("Head") or char:WaitForChild("Head")
if not head then
	repeat wait() until head
	char = char:FindFirstChild("Head")
end
--///////////////////////
local rightLeg = char:FindFirstChild("Right Leg") or char:WaitForChild("Right Leg")
local leftLeg = char:FindFirstChild("Left Leg") or char:WaitForChild("Left Leg")
local RS = game:GetService("RunService")
local Workspace = game:GetService("Workspace")









if leftLeg and rightLeg then
	local leftA = Instance.new("Attachment")
	local rightA = Instance.new("Attachment")
	leftA.Visible = true
	rightA.Visible = true
	leftA.Parent = leftLeg
	rightA.Parent = rightLeg
	RS.RenderStepped:Connect(function()
		local rightRayOrigin = rightLeg.Position
		local rightRayDirection = Vector3.new(0, 5, 0)
		local rightRaycastParams = RaycastParams.new()
		rightRaycastParams.FilterDescendantsInstances = {player.Character}
		rightRaycastParams.FilterType = Enum.RaycastFilterType.Exclude
		local rightRaycastResult = Workspace:Raycast(rightRayOrigin, rightRayDirection, rightRaycastParams)
		print(rightRaycastResult.Instance)
		
		rightA.Position = rightRaycastResult.Normal
	end)

and this error occurs on this line?

rightRaycastParams.FilterDescendantsInstances = {player.Character}

No, this one

print(rightRaycastResult.Instance)

and so what did it print previously when you listed each body part?

Handle - Client - Animate:58, which I believe to be referencing the handle parts under the accessories in the character. That’s when I realized that there has to a more efficient way of doing this.

what if you make the ray have more range then, see if that works:

local rightRayDirection = Vector3.new(0, 30, 0)

Nope, same error. Is there a way to limit the actual direction of the raycast to one direction (that direction being down)?

wait… im so dumb…

local rightRayDirection = Vector3.new(0, -30, 0)

yeah, thanks for the reminder, now that should be DOWN, instead of up lmao

1 Like

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