I’m trying to make an AI need to have line of sight of the player to follow them, but whenever the AI gets close to a wall, it can’t get line of sight even though it should. I’ve tried to set an offset for the ray origin but that didn’t fix anything.
Line of Sight Function:
function EnemyModule:IsInLineOfSight(StartPosition, EndPosition, Target, Excluding)
local RaycastParameters = RaycastParams.new()
RaycastParameters.FilterType = Enum.RaycastFilterType.Exclude
RaycastParameters.FilterDescendantsInstances = { Target, Excluding }
local RayResult = workspace:Raycast(StartPosition, EndPosition, RaycastParameters)
if not RayResult then
return true
end
return false
end
local LineOfSightOrigin = EnemyHead.Position + Vector3.new(0, EnemyHead.Size.Y/2 + 0.5, 0)
local TargetLineOfSight = self:IsInLineOfSight(LineOfSightOrigin, EntityPosition, TargetHead, EnemyCharacter)
Video Demonstration: https://gyazo.com/ee350dc5fcb8a1c9a9eb483a9a4627d1