On the problem of recastnavigation finding the result anomaly.

Source: Internet
Author: User

As the pathfinding solution used by our project is: The client uses Unity's native pathfinding system, the server uses the Recastnavigation system, and the server's pathfinding data is derived from unity, so theoretically both sides of the search result should be the same, but in fact not, Unity can show more natural results in any case, but the server can sometimes have more bizarre results.

From the above three can be seen, the starting point and the end of a little bit of change, the result will be a large difference, the search results will often "turn", this result is bound to be unacceptable, unity will not appear in this situation, after many tests and careful review and analysis, found that the search grid appears too "slender" Triangle caused, that how to modify it, I in the official forum to the author (Mikko Mononen) questions (the original address point here, solve fanqing problem by itself): 1. I think Unity's pathfinding system is based on the original author's Recastnavigation system; 2. Whether this result is caused by the "slender" triangle, how to solve it?

Very happy the author soon recovered: the 1.unity pathfinding system was actually written based on Recastnavigation, but the detour system has been rewritten in depth (and later found that the author's Twitter profile is Unity's AI programmer); 2. This problem is really due to " Elongated "triangle, NavMesh system when encountering a particularly wide or three-side length of a triangle with a particularly large problem. The author described the problem in his blog long ago and gave a solution, blog address:

http://digestingduck.blogspot.fi/2010/05/towards-better-navmesh-path-planning.htmlhttp:// The digestingduck.blogspot.fi/2010/08/visibility-optimized-graph-experiment.html solution is to change the placement of nodes in a * search result, NavMesh The system uses the midpoint of the polygon edge as the path through the point, if you want to lot better the result, you should use the nearest point, that is, you have a, a two points on the two sides of a segment L, then this point should be the intersection of Line AB and line L.
1 if(Neighbournode->flags = =0)2 {3    floatsa[3], sb[3];4 getportalpoints (Bestref, Bestpoly, Besttile,5 neighbourref, Neighbourpoly, Neighbourtile,6 SA, SB);7    floatt =0.5f;8 dtdistanceptsegsqr2d (Endpos, SA,SB, T);9t = Dtclamp (t,0.1f,0.9f);TenDtvlerp (neighbournode->Pos, SA,SB, T); One}

This code is in the following sections:

https://github.com/memononen/recastnavigation/blob/master/Detour/Source/DetourNavMeshQuery.cpp#L1029https:// Github.com/memononen/recastnavigation/blob/master/detour/source/detournavmeshquery.cpp#l1321 can also use the bestNode- >pos "replaces" endpos "so that the" nearest "point can be used to replace the" end point "in the current *, while the author points out that the solution of the client and server like me can only be adjusted to optimize the visual results, and there is no one hundred percent accurate solution,   However, it is very happy that this modification of an experiment, it turns out that "normal", and now the client and server pathfinding 90% of the situation can be consistent, very individual circumstances will be different, but the results will not be particularly "strange", so it is very satisfied, too grateful to the original author Mikko classmates. aside, this little piece of code was originally usedGetedgemidpointTo find the midpoint, the author usesdtdistanceptsegsqr2dThis function is used to calculate the intersection point of the vertical distance line of the Endpos to the line of SA and SB t,t the value of the segment Sa-t and the length of the segment T-SB. Of course this result is good, but not the best, the author of the original blog using Dtintersectsegseg2d (AP, AQ, BP, BQ, S, T), calculated is the line segment Ap-aq and segment BP-BQ intersection m on the ratio of two segments S = | | ap-m| | / || m-aq| |,t = | | bp-m| | / || m-bq| |, in this way the real nearest distance is calculated, the shortest line between two points; This function is very interesting, the internal use of pertdotproduct this mathematical formula, this is the most interesting, but not very easy to understand, that is, vector A and vector B The pertdotproduct result is: A's normal vector and the dot product of vector B, the geometric meaning is the area of the parallelogram of two segments (| | a| |.| | b| |. Sina), and the ratio of the intersection of two segments to each segment is precisely calculated by calculating the ratio of pertdotproduct, because they form a parallelogram of a common bottom, so the ratio of area to height is equal to The height is exactly the distance from the beginning of one line segment to the point of intersection and from the beginning to the end point.  My own solution is to choose the last kind of dtintersectsegseg2d, the effect is also the best. Recently has been too busy, have not updated, in fact, accumulated a lot of experience in my impression notes, slowly add to it here.

On the problem of recastnavigation finding the result anomaly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.