Created
September 18, 2021 22:54
-
-
Save repsejnworb/c68e0875c13e0605482cd3ae58f9aead to your computer and use it in GitHub Desktop.
client predicted top down example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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