Boxing Game update 9 (22/01/24)


For this session I wanted to add a player death condition and make dodging temporary.

Player Header File

FVector StartLocation;
...
void Damage();

The start location is stored to reset player position shortly after a dodge, and the damage function will monitor player health.

Player C++ file

void ACompetitionCharacter::BeginPlay()
...
StartLocation = GetActorLocation();
...
void ACompetitionCharacter::OnOverlapStart()
...
if (OtherComp == (Enemy->LeftArmBox))
{
Damage();

Above I set the start location at the beginning of runtime, I also replaced the player damage with the damage function.

void ACompetitionCharacter::Damage()
{
health = health - 25;
//if player health is less than or zero, quit game
if (health <= 0)
{
UKismetSystemLibrary::QuitGame(this->GetWorld(), this->GetWorld()->GetFirstPlayerController(), EQuitPreference::Quit, true);
...
void ACompetitionCharacter::Retreat()
...
//reset location after timer elapsed
ACompetitionCharacter::SetActorLocation(StartLocation);

Now the game will exit when the player is killed and the player will move back to their start location after dodging temporarily.


Leave a Reply

Your email address will not be published.