Yaay! I’m glad to have helped out!
That was actually the most complex part, I did a bunch of geometric tests to identify the proper points using FBox and line tests.
After obtaining the FBox that represents each poly, I then did a bunch of tests to see which one was the best for the unit to use
Here’s the function I created in my custom PathFollowingComponent to initiate my geometric tests:
//Verts
bool NavPoly_GetVerts(const NavNodeRef& PolyID, TArray<FVector>& OutVerts);
//Bounds
FBox NavPoly_GetBounds(const NavNodeRef& PolyID);
//Choose Which Nav Data To Use
FORCEINLINE const ANavigationData* JoyGetNavData() const
{
const FNavAgentProperties& AgentProperties = MovementComp->GetNavAgentPropertiesRef() ;
const ANavigationData* NavData = GetNavDataForProps(AgentProperties) ;
if (NavData == NULL)
{
NavData = GetMainNavData();
}
return NavData;
}
//~~~
bool UJoyPathFollowCompHighest::NavPoly_GetVerts(const NavNodeRef& PolyID, TArray<FVector>& OutVerts)
{
//Get Nav Data
const ANavigationData* NavData = JoyGetNavData();
const ARecastNavMesh* NavMesh = Cast<ARecastNavMesh>(NavData);
if(!NavMesh)
{
return false;
}
return NavMesh->GetPolyVerts(PolyID,OutVerts);
}
//Get Box of individual poly from verts
FBox UJoyPathFollowCompHighest::NavPoly_GetBounds(const NavNodeRef& PolyID)
{
TArray<FVector> Verts;
NavPoly_GetVerts(PolyID,Verts);
FBox Bounds(0);
for(const FVector& Each : Verts)
{
Bounds+=Verts;
}
return Bounds;
}
**Geometric Analysis Using FBox**
I had to do all the geometric analysis myself!
I recommend you check out all the convenience functions in:
**UnrealMathUtility.h**
and
**Box.h**
These are the basic tools you can use to do the analysis yourself to find the best spot!
Essential Function
I especially recommend checking out a fast trace you can do using a Line Box intersection:
UnrealMathUtility.h
/** Determines whether a line intersects a box. */
static bool **LineBoxIntersection**( const FBox& Box, const FVector& Start, const FVector& End, const FVector& Direction );
/** Determines whether a line intersects a box. overload avoids the need to do the reciprocal every time. */
static bool** LineBoxIntersection**( const FBox& Box, const FVector& Start, const FVector& End, const FVector& Direction, const FVector& OneOverDirection );
/* Swept-Box vs Box test */
static CORE_API bool **LineExtentBoxIntersection**(const FBox& inBox, const FVector& Start, const FVector& End, const FVector& Extent, FVector& HitLocation, FVector& HitNormal, float& HitTime);
**Multi-Threading**
I multi-threaded my final solution to result in best performance.
Good Luck!
I look forward to hearing about your chosen implementation!