Please help. All progress I’ve made is a way to see on which side of a wall should the npc hide and a really bad way to find the corners of a part.
Is this something you still need help with?
Yes. I do still need help with this
Assuming you have a working pathfinding script already, you add a function for the cover position and you run it based on the conditions you want to be met
You could choose random points (1) nearby the AI (2) and cast a ray (3) from that point to the attacker (4). If the ray is blocked by a potential barrier, then shoot a few more rays (5) in that direction from points much closer nearby to make sure there is secure space and that there’s not only like one little pole blocking the first ray from hitting.
Then, do that with every ray, and then find the closest successfully blocked ray position, and dive there. If none are found, then expand the radius and try again. You might want to mess around with actors for this.
If you’re confused, let me know.
The easy part is figuring out whether cover is protective or not, simply determine a height for cover to be effective and see if a raycast from the attacker is obstructed from that spot.
The difficult part is figuring out where to take cover. You could manually add spots all over the map that the AI checks as cover, but that doesn’t work if the map has changing elements and is also time-consuming to do.
@Chiseled_Cheese’s solution is a good start, but it’d be better if the raycasts were fired from the NPC in 6-12 angles around it equally. Firing randomly may take a long time to find cover or miss what would seem like obvious cover. Anyways, once a ray hits something, it checks if the position is safe from the attacker with the check mentioned earlier.