I have a module script that is supposed to detect the ground by having several origins and looping through them. However, the script doesn't detect anything. I don't really understand raycasting well, so I have no idea what I'm missing here.
Module for Detecting Ground
function groundDetection:set(Character)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Character}
raycastParams.IgnoreWater = true
local humanoidRoot = Character.HumanoidRootPart
local xRange = 0.95
local yRange = 3.05
local zRange = 0.475
local origins =
{ humanoidRoot.Position,
humanoidRoot.CFrame.RightVector*xRange, humanoidRoot.CFrame.RightVector*-xRange,
humanoidRoot.CFrame.LookVector*zRange, humanoidRoot.CFrame.LookVector*-zRange,
}
local hitParts = {}
for i,origin in pairs(origins) do
local newOrigin = Vector3.new(origin)
local destination = CFrame.new(origin).UpVector * -yRange
local raycastResult = workspace:Raycast(newOrigin, destination, raycastParams)
if raycastResult then
local distance = (origin - raycastResult.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(origin, raycastResult.Position)*CFrame.new(0, 0, -distance/2)
table.insert(hitParts, raycastResult.Instance:GetFullName())
end
end
print(hitParts)
end
