's Get Random Point in Radius For You
Here’s the wrapper I wrote!
I use this inside a custom Path Follow component.
I have wiki on how to set up a custom Follow Component here:
Custom AI Path Follow Components In UE4
**Get Random Point in Radius**
```
//YourPathFollowComponent.h
bool GetRandomPointInRadius(const FVector& Origin, float Radius, FVector& OutResult);
//.cpp
bool UJoyPathFollowCompHighest::GetRandomPointInRadius(const FVector& Origin, float Radius, FVector& OutResult)
{
UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(GetWorld());
if(!NavSys)
{
return false;
}
//~~~~~~~~~~~~~
FNavLocation Result;
//This is a wrapper for UE4 version
bool bSuccess = NavSys->GetRandomPointInRadius(Origin, Radius, Result);
//Out
OutResult = Result.Location;
return bSuccess;
}
```
Core Code, Usable Anywhere
You dont really need to put this in a PathFollowComponent, you can just run the code anywhere!
UNavigationSystem* NavSys = **UNavigationSystem::GetCurrent**(GetWorld());
if(!NavSys)
{
//could not get UE4 Nav system
return;
}
//~~~~~~~~~~~~~
FNavLocation Result;
bool bSuccess = NavSys->**GetRandomPointInRadius**(Origin, Radius, Result);
if(!bSuccess)
{
//report non success case
return;
}
//Success!
//FVector result is
**//Result.Location**
Enjoy!
:)