Answered by
6 years ago Edited 6 years ago
I'm not aware of anything related to the PFS which will do this for you.
I would recommend just activating a .Changed event on the AI's humanoid to see when they are shot at or hurt and then search for the closest area of cover. You can do this by naming all parts in Workspace that can be used as cover something specific and then simply use magnitude to find out which one is the closest and navigate to it using PFS. Here's an example.
02 | local ClosestDistance = 10000000 |
04 | for _,a in pairs (workspace:GetChildren()) do |
05 | if (a.Name = = 'Cover' ) then |
06 | local dis = (robot.Torso.Position - a.Position).magnitude |
07 | if (dis < ClosestDistance) then |
16 | robot.Humanoid.Changed:Connect( function (prop) |
17 | if (prop = = 'Health' ) then |
18 | local cover = findCover() |
Of course, you'll need to include a check to determine when combat is over or the threat is gone and then proceed as normally.