cc @Cedric our NavMesh genius
To make an agent stop, set its destination to be its current position.
Hi Cedric, I’m really glad that you took the time.
The problem is probably that I do not understand how to calculate that it’s time to stop. After all, the usual calculation of the hypotenuse will not work, the shortest distance to the target can be through a wall (obstacle, building, rock, etc.), that is, the actual distance to the target along the path that is calculated by navigation will be greater. I understand that the path from the points can be obtained through RecastJSPlugin.computePath, but how can I calculate the required distance using these points?
the points returned by computePath compose a list of segments. You can calculate the distance between each points and sum it. this will give you the length of the path.
And it’s me again. Good day. Yesterday it dawned on me that I may be in vain attached to the route, and you can try using ray casting. Today I experimented, taking into account Cedric’s advice - it turned out that calculating the length of the route does not suit me - the possibility of “attacking from around the corner” appears when the range is less. With the rays, too, everything turned out to be not so simple, due to the agents pushing each other, the beam went to the side and the accuracy became random But returning to the calculation of the route length, I noticed that there are always two points on the line (who would have thought that the segment consists of two dots, haha :slight_smile: ). Unfortunately, this did not solve my problem, either. when going around the sphere, you could visually look straight, but a slight bend gives an extra point, because of which everything breaks again.
As a result, after trying various combinations, it dawned on me that it is possible to filter out the final segment if it is small (a small price, a bevel of a small corner, so as not to do a bunch of checks and conditions, sacrificing performance).
What I want to say - that’s what I did, it works acceptable, thanks to Cedric for the idea, for some reason it was completely unobvious for me