Add Respawn Point to Prevent Restarting Whole Level

This commit is contained in:
Philip W 2023-11-09 13:32:37 +00:00
parent ac1400019c
commit 00011764c3
3 changed files with 16 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -204,8 +204,18 @@ float AEndlessVendettaCharacter::TakeDamage(const float DamageAmount, FDamageEve
GetWorld()->GetTimerManager().ClearTimer(RegenHealthTimerHandle);
}
UE_LOG(LogTemp, Warning, TEXT("Player is dead"));
UGameplayStatics::OpenLevel(this, FName(*GetWorld()->GetName()), false);
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsWithTag(GetWorld(), FName(TEXT("Respawn")), FoundActors);
if (FoundActors.Num() > 0)
{
const AActor* RespawnPoint = FoundActors[0];
SetActorLocationAndRotation(RespawnPoint->GetActorLocation(), RespawnPoint->GetActorRotation());
CurrentHealth = MaxHealth;
return Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
}
UGameplayStatics::OpenLevel(this, FName(*GetWorld()->GetName()), false);
return Super::TakeDamage(DamageAmount, DamageEvent, EventInstigator, DamageCauser);
}