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.
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.
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)
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.