I’m working on an fps AI system, and I want it to determine a viable cover point based on a folder in the workspace containing parts representing those points.
My way of checking if a point is viable is finding all nearby points, then firing a raycast to see if they’re not in view of the nearest player, However I noticed that the AI only decides to work for a specific cover point
This is all really hard to explain, so here’s a video:
https://gyazo.com/5e9f1d05f4ea85e4fffbcc63da8bf58c
Code:
function FindCover(Target)
local Cover = nil
if workspace:FindFirstChild("CoverPoints") then
for i,v in ipairs(workspace.CoverPoints:GetChildren()) do
local Point = v
if Point then
if (HumanoidRootPart.Position - Point.Position).magnitude < MaximumDistance.Value then
print(v)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {Character,workspace.CoverPoints,Target.Parent}
Cover = Point
local Raycast = workspace:Raycast(Cover.Position, (Target.Position - Cover.Position), raycastParams)
if Raycast then
Cover = Point
else
Cover = nil
end
end
end
print("CompleteLoop")
end
end
if Cover ~= nil then
print("Found Cover: "..Cover.Name)
end
return Cover
end
The AI then pathfinds toward the cover point