FPS AI consistently ignores specific coverpoint

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

I’m thinking if both of the cover points are valid for the AI to go to them, you don’t actually perform any other decision in determining which cover point to traverse to, so in theory the AI will end up going to the same one every time if both of the points are valid.

Could a solution be to have the AI traverse to the cover point that is closer to itself?

On a side note I noticed your direction argument in your Raycast call is not normalized, so this may also yield unexpected/inconsistent results.

local raycastDir = (Target.Position - Cover.Position).Unit * MAX_DISTANCE_CONST
local Raycast = workspace:Raycast(Cover.Position, raycastDir, raycastParams)

Well I fixed the raycast as you said, the raycasts were actually giving weird results, such as the ground, and the object behind it for some reason.

I keep making edits as I experiment, but after some messing around I came to a compromise, the AI will move to the first point that it considers valid if there’s no points then it simply stands still and continues another branch of options.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.