I’m working on some simple enemy AI, it’s a drone so I’m not using pathfinding. Instead when a player is detected inside of it’s range it casts a ray towards the player to confirm visibility and then attacks the player.
However, the ray seems to be casting in the right direction only half of the time as can be seen in this video. (The issue appears at about half of the video, the blue parts represent the position where the ray hit, they are added to the ignorelist to make sure the ray doesn’t hit them)
robloxapp-20200526-0008434.wmv (4.9 MB)
Raycasting has been my downfall for a while already and here I am completely confused again so I thought I’d ask for some help.
--raycast towards the player to check visibility
--closest part is the closest humanoidrootpart present in the region
local checkRay = Ray.new(closestPart.Position, (drone.Position - closestPart.Position).unit * range)
local checkPart, checkPosition = workspace:FindPartOnRayWithIgnoreList(checkRay, ignorelist, false, true)