Skip to content

Instantly share code, notes, and snippets.

@repsejnworb
Created September 18, 2021 22:54
Show Gist options
  • Select an option

  • Save repsejnworb/c68e0875c13e0605482cd3ae58f9aead to your computer and use it in GitHub Desktop.

Select an option

Save repsejnworb/c68e0875c13e0605482cd3ae58f9aead to your computer and use it in GitHub Desktop.
client predicted top down example
void AgastCharacterV2::BeginPlay()
{
Super::BeginPlay();
NavDestination = GetActorLocation();
}
void AgastCharacterV2::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
GetNextPathPoint();
}
void AgastCharacterV2::SetNavDestination(const FVector& DestLocation)
{
NavDestination = DestLocation;
}
FVector AgastCharacterV2::GetNextPathPoint()
{
if ((NavDestination - GetActorLocation()).Size() <= 100.f)
{
return GetActorLocation();
}
UNavigationPath* NavPath = UNavigationSystemV1::FindPathToLocationSynchronously(this, GetActorLocation(), NavDestination);
if (NavPath->PathPoints.Num() > 1)
{
if ((NavPath->PathPoints[(NavPath->PathPoints.Num() - 1)] - GetActorLocation()).Size() <= 100.f)
{
return GetActorLocation();
}
FVector ForceDirection = NavPath->PathPoints[1] - GetActorLocation();
GetMovementComponent()->RequestPathMove(ForceDirection);
return NavPath->PathPoints[1];
}
else
{
return GetActorLocation();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment