File size: 1,396 Bytes
8d44bc8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | // Copyright Epic Games, Inc. All Rights Reserved.
#include "CombatCheckpointVolume.h"
#include "CombatCharacter.h"
#include "CombatPlayerController.h"
ACombatCheckpointVolume::ACombatCheckpointVolume()
{
// create the box volume
RootComponent = Box = CreateDefaultSubobject<UBoxComponent>(TEXT("Box"));
check(Box);
// set the box's extent
Box->SetBoxExtent(FVector(500.0f, 500.0f, 500.0f));
// set the default collision profile to overlap all dynamic
Box->SetCollisionProfileName(FName("OverlapAllDynamic"));
// bind the begin overlap
Box->OnComponentBeginOverlap.AddDynamic(this, &ACombatCheckpointVolume::OnOverlap);
}
void ACombatCheckpointVolume::OnOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// ensure we use this only once
if (bCheckpointUsed)
{
return;
}
// has the player entered this volume?
ACombatCharacter* PlayerCharacter = Cast<ACombatCharacter>(OtherActor);
if (PlayerCharacter)
{
if (ACombatPlayerController* PC = Cast<ACombatPlayerController>(PlayerCharacter->GetController()))
{
// raise the checkpoint used flag
bCheckpointUsed = true;
// update the player's respawn checkpoint
PC->SetRespawnTransform(PlayerCharacter->GetActorTransform());
}
}
}
|