In order for my archer to shoot the player he has to have a clear line of sight of the player.
I was wondering if there is a way to find a location from which he can shoot at the player by using Unity’s NavMesh system in combination with raycasts, or maybe some other method.
I calculate concentric rings around my NPCs target. I find locations left and right 15 degrees of the current angle, then back 5 yards and forwards 5 yards depending on if they are in the right distance range. I then see first if the position can see the target with a raycast then navmesh.samplepositon to see if the position is even possible to reach. I also do a raycast between the two points to be sure there are no obstructions. This causes the ai to always be circle strafing while testing to keep line of sight. If there are no available positions, the nav defaults to the target position to make it follow the player.
I’ve been trying to implement it but I ran into a problem when it came to knowing if the agent can go to to the point on the navmesh.
You mentioned using NavMeshAgent.Raycast(): The raycast provides the information if there is something that blocks the path linearly to the destination. That’s not what I want, I want to know if there is a way, even if it’s not linear, to get to the destination.
or using NavMeshAgent.SamplePathPosition(): I don’t know what to set in the in maxDistance value, I set it to 1000 for testing purposes and it’s always giving me back the info that the agent can walk to the destination but it’s true.
How can I test if an Agent will be able to walk to a destination?