Raycasting is ignoring/ missing its intended target

  1. What do you want to achieve?
    I want to raycast between these 2 NPCs.
  2. What is the issue?

    This is a visualization of what is happening. The ray seems to either ignore the soldier or miss it completely.
  3. What solutions have you tried so far?
    I have just been troubleshooting this. I know the soldier is ignored or missed. Every other basepart that touches the ray registers.
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {zombie}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist

while true do
	local origin = zombie.Head.Position
	local direction = soldier.HumanoidRootPart.Position
	
	local raycastResult = workspace:Raycast(origin, direction)

	if raycastResult then
		local distance = (zombie.Head.Position - raycastResult.Instance.Position).Magnitude
		local p = Instance.new("Part", workspace.Folder)

        --Visualization
		p.Anchored = true
		p.CanCollide = false
		p.Size = Vector3.new(0.1, 0.1, distance)
		p.CFrame = CFrame.lookAt(zombie.Head.Position, raycastResult.Instance.Position)*CFrame.new(0, 0, -distance/2)
		
		if raycastResult.Instance.Parent == soldier then
			zombie.Humanoid:MoveTo(soldier.HumanoidRootPart.Position)
			print("Target seen")
		else
			print(raycastResult.Instance)
			print(raycastResult.Normal)
		end
	end
	
	wait()
end

The direction parameter is not the end position of the ray, it’s the direction the ray is going in. The direction parameter should be:

	local direction = soldier.HumanoidRootPart.Position - zombie.Head.Position

The direction is okay now, but it is still not registering the other NPC, even though the ray goes right through it.