Part detecting players in front of its field of view

I’m having trouble with zombies detecting players within its field of view while limiting the Y-Axis radius (so they can pathfind up to the top or other floors above the players without the zombie detecting the player on the room and go straight towards its direction thus slamming onto the wall).

What I mean by limited the Y-Axis radius, is limiting how far the ray can detect on the Y-Axis (ex. 5 studs)

1 Like

Rundown


Can you provide the raycast code, if you have one? – We’re blind like bats if we don’t have the original code.

@Nyonic
That’s overcomplicated.

if math.abs(Zombie.HumanoidRootPart.Position.Y - Player.HumanoidRootPart.Position.Y) < 5 then
    -- your code if it is in correct height
end
1 Like
local Hit, Position = workspace:FindPartOnRayWithIgnoreList(Ray.new(self.Torso.Position, self.Target.Position - self.Torso.Position), Ignorelist)	
if Hit ~= nil then
	print(Hit)
	if Hit == self.Target or Hit:IsDescendantOf(self.Target.Parent) then
		print( "icu yo ;)" )
		self.TargetIsInView = true
	end											
	if not Hit.CanCollide or Hit.Transparency > 0.5 then
		Ignorelist[#Ignorelist+1] = Hit
	end
end

Actually never mind, this will do.