0. 개요

던전 입구 등의 액터를 클릭하면 해당 대상에게 이동하도록 설정한다.

 

 

1. 적이 아닌 대상을 클릭하면 특정 위치로 이동하기

(1) HighlightInterface에 함수 선언

	UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
	void SetMoveToLocation(FVector& OutDestination);

적이 아닌 어떤 액터를 대상으로 클릭하면 특정 위치로 이동하도록 벡터를 수정하여 내보내는 함수를 선언한다.

 

 

(2) Checkpoint에서 인터페이스 함수 오버라이드

먼저 체크포인트가 해당 인터페이스를 상속받도록 한다.

UCLASS()
class AURA_API ACheckPoint : public APlayerStart, public ISaveInterface, public IHighlightInterface
{

- 이전 포스트에서 블루프린트 내에 구현했던 인터페이스 이벤트는 모두 제거한다.

해당 작업을 C++ 코드에서 구현할 것이다.


	/* HighlightInterface 오버라이드*/
	virtual void HighlightActor_Implementation() override;
	virtual void UnHighlightActor_Implementation() override;
	virtual void SetMoveToLocation_Implementation(FVector& OutDestination) override;
	/* HighlightInterface 끝*/
void ACheckPoint::HighlightActor_Implementation()
{
	CheckpointMesh->SetRenderCustomDepth(true);
}

void ACheckPoint::UnHighlightActor_Implementation()
{
	CheckpointMesh->SetRenderCustomDepth(false);
}

블루프린트에서 구현했던 하이라이트 작업을 C++에서 구현한다.

 

(2-1) 체크 포인트의 생성자 수정

	UPROPERTY(EditDefaultsOnly)
	int32 CustomDepthStencilOverride = CUSTOM_DEPTH_TAN;

먼저 멤버 변수로 커스텀 뎁스 스텐실 값을 선언한다.

 

ACheckPoint::ACheckPoint(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
	PrimaryActorTick.bCanEverTick = false;

	CheckpointMesh = CreateDefaultSubobject<UStaticMeshComponent>("CheckpointMesh");
	CheckpointMesh->SetupAttachment(GetRootComponent());
	CheckpointMesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
	CheckpointMesh->SetCollisionResponseToAllChannels(ECR_Block);
	CheckpointMesh->SetCustomDepthStencilValue(CustomDepthStencilOverride);
	CheckpointMesh->MarkRenderStateDirty();

하이라이팅할 때마다 뎁스 스텐실 값을 바꾸지 않고 생성자에서 변경 후 강제 적용하도록 한다.

 

 

(2-2) 액터 내의 움직일 목적지가 되는 씬 컴포넌트를 멤버 변수로 추가

	UPROPERTY(VisibleAnywhere)
	TObjectPtr<USceneComponent> MoveToComponent;
	// MoveToLocation의 목적지
	MoveToComponent = CreateDefaultSubobject<USceneComponent>("MoveToComponent");
    	MoveToComponent->SetupAttachment(GetRootComponent());

생성자에서 생성한다.

 

 

(2-3) SetMoveToLocation 함수 오버라이드

void ACheckPoint::SetMoveToLocation_Implementation(FVector& OutDestination)
{
	OutDestination = MoveToComponent->GetComponentLocation();
}

 

 

(2-4) AuraPlayerController의 AbilityInputTagReleased 함수 수정 - 클릭으로 이동하기

void AAuraPlayerController::AbilityInputTagReleased(FGameplayTag InputTag)
{
    // 입력 상태 태그 확인
    if (GetASC() && GetASC()->HasMatchingGameplayTag(FAuraGameplayTags::Get().Player_Block_InputReleased))
    {
        return;
    }

    // 더 이상 왼쪽 클릭 태그가 아닐 경우
    if (!InputTag.MatchesTagExact(FAuraGameplayTags::Get().InputTag_LMB))
    {
        if (GetASC())
            GetASC()->AbilityInputTagReleased(InputTag);

        return;
    }

    if (GetASC())
        GetASC()->AbilityInputTagReleased(InputTag);

    // 타겟이 없고 쉬프트키가 눌리지 않았다면
    if (TargetingStatus != ETargetingStatus::TargetingEnemy && !bShiftKeyDown)
    {
        // 경계값보다 짧게 눌렀으면 목적지로 길 찾기 시작
        const APawn* ControlledPawn = GetPawn();
        if (FollowTime <= ShortPressThresold && ControlledPawn)
        {
            if (IsValid(ThisActor) && ThisActor->Implements<UHighlightInterface>())
            {
                IHighlightInterface::Execute_SetMoveToLocation(ThisActor, CachedDestination);    
            }

이제 ThisActor는 클릭한 대상 액터를 가리키고 있다.

해당 액터의 SetMoveToLocation 함수를 실행한다.

 

 

(2-5) AuraEnemy에서 SetMoveToLocation 함수가 작동하지 않도록 오버라이드

void AAuraEnemy::SetMoveToLocation_Implementation(FVector& OutDestination)
{
    // 절대 건드리지 마시오
}

잘못 작동하지 않도록 함수의 내용을 비운다.

 

 

(3) BP_CheckPoint의 MoveToComponent의 위치 조정

해당 액터를 클릭하면 MoveTo 컴포넌트의 위치까지 이동하게 된다. 해당 컴포넌트의 위치를 조정한다.