How would i raycast humanoidrootpart to floor correctly?

  1. What do you want to achieve?
    R= I want to get the cylinder extactly under the character with the raycast.

  2. What is the issue? Include screenshots / videos if possible!
    R = The cylinder it’s not going in the correct position and just keeps going above the character, and giving 0,-8,0 as result no matter what i edit.


  1. What solutions have you tried so far?
    R = messing up with positions, changing characters and etc and haven’t found any solution.

Here is the code that i used with a normal character, giving the same results as the screenshot.

local Character = script.Parent
local root = Character:FindFirstChild("HumanoidRootPart")


local function SendRayCast(Character, RootPart)
	local RayOrigin = RootPart.Position
	local RayDirection = Vector3.new(0, -100, 0) 

	local RayParams = RaycastParams.new()

	RayParams.FilterType = Enum.RaycastFilterType.Exclude
	RayParams.FilterDescendantsInstances = {
		Character,
		--PlayerCharacter
	}

	local Result = workspace:Raycast(RayOrigin, RayDirection, RayParams)

	if Result then
		local ResultInstance = Result.Instance	
		print(ResultInstance.Position)
		return ResultInstance

	else
		return nil
	end
end


local function SendDestRayCast(Character, RootPart)
	local RayCastResult = SendRayCast(Character, RootPart)

	if RayCastResult ~= nil then
		--print(RayCastResult.Position)
		print(RayCastResult.Name)
		print(RayCastResult.Parent)
		return RayCastResult.Position
	end
end

while task.wait(1) do
local Pool = Instance.new("Part")
Pool.Shape = Enum.PartType.Cylinder
Pool.CanCollide = false
Pool.Anchored = true
Pool.Parent = workspace
Pool.Size = Vector3.new(0.15, 10.359, 10.241)
Pool.Rotation = Vector3.new(0,90,90)

local Result = SendDestRayCast(Character, root)
if Result ~= nil then
	Pool.Position = root.Position - Vector3.new(0, Result.Y, 0)
end

end

I hope you can help me with this problem!

If the circle should appear directly below the player on the ground, you can use Result.Position and Result.Normal.

local Character = script.Parent
local root = Character:FindFirstChild("HumanoidRootPart")


local function SendRayCast(Character, RootPart): RaycastResult
	local RayOrigin = RootPart.Position
	local RayDirection = Vector3.new(0, -100, 0) 

	local RayParams = RaycastParams.new()

	RayParams.FilterType = Enum.RaycastFilterType.Exclude
	RayParams.FilterDescendantsInstances = {
		Character,
		--PlayerCharacter
	}
	return workspace:Raycast(RayOrigin, RayDirection, RayParams)
end



while task.wait(1) do
	local Pool = Instance.new("Part")
	Pool.Shape = Enum.PartType.Cylinder
	Pool.CanCollide = false
	Pool.Anchored = true
	Pool.Parent = workspace
	Pool.Size = Vector3.new(0.15, 10.359, 10.241)
	Pool.Rotation = Vector3.new(0,90,90)

	local Result = SendRayCast(Character, root)
	if Result then
		Pool.Position = (Result.Position + Result.Normal*Pool.Size.Y/2)
	end
end
1 Like