Help with finding the distance between a part and the closest point that a ray hits

local ListOfIgnoredObjects = {}
for _, Object in next, workspace.CurrentMap:GetDescendants() do
	if Object:IsA"BasePart" and not Object.CanCollide then
		table.insert(ListOfIgnoredObjects, Object)
	end
end
for _, Object in next, Humanoid.Parent:GetChildren() do
	if Object:IsA"BasePart" then
		table.insert(ListOfIgnoredObjects,Object)
	end
end
local HRPPos = HumanoidRootPart.Position
print((HRPPos-(workspace:Raycast(HRPPos,DownwardVector,RaycastParams.new(ListOfIgnoredObjects,Enum.RaycastFilterType.Blacklist))).Position).Magnitude)

It printed some value that is a bit too low, when in fact the distance between the player and the ground at least 30 studs
DownwardVector is a constant with the value Vector3.new(0,-1,0)

You need to multiply the direction with a unit.

Vector3.new(0, -1, 0) * 9e9
1 Like

It seems like DownwardVector value has to be lower as it only checks objects within the range.

Vector3.new(0,SomeLength,0)

Also RaycastParams.new() Here seems to be messed up.
It should be formatted like this:

local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.FilterDescendantsInstances = {...}