보별 2025. 6. 11. 10:22

Enemy Groggy State 구현

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
49
50
51
52
53
54
55
if (Damage > 0)
{
    GEngine->AddOnScreenDebugMessage(-13.0f, FColor::Blue, FString::Printf(TEXT("Damage Taken")));
    EnemyHP -= Damage;
 
    if (enemyType == EEnemyType::Kallari && KallariHitMontage.Num() > 0 && isGroggy == false)
    {
        UAnimInstance* animInstance = GetMesh()->GetAnimInstance();
        int randomInt = FMath::RandRange(0, KallariHitMontage.Num() - 1);
        if (animInstance)
        {
            animInstance->Montage_Play(KallariHitMontage[randomInt]);
        }
            
        UGameplayStatics::PlaySound2D(GetWorld(), KallariHitSound);
    }
 
.
.
.
    if (enemyType == EEnemyType::Kallari && KallariGroggyMontage.Num() > 0 && EnemyGP <= 0 && isGroggy == false)
    {
        isGroggy = true;
    
        AAIController* AIController = Cast<AAIController>(GetController());
        if (AIController)
        {
            AIController->GetBrainComponent()->StopLogic(TEXT("")); // AIController를 가져와 Logic을 중단시킴 -> BT 동작을 중지하고 아래 과정 진행; StopLogic 옆에 TEXT는 중지 이유를 설명하기에 반드시 TEXT가 있어야함
        }
        
        UAnimInstance* animInstance = GetMesh()->GetAnimInstance();
        int randomInt = FMath::RandRange(0, KallariGroggyMontage.Num() - 1);
        if (animInstance)
        {
            animInstance->Montage_Play(KallariGroggyMontage[randomInt]);
        }
 
        UGameplayStatics::PlaySound2D(GetWorld(), KallariHitSound);
 
        GetWorld()->GetTimerManager().SetTimer(GroggyTimerHandle, [this, AIController]()
            {
                isGroggy = false;
                EnemyGP = 50;
                if (AIController)
                {
                    AIController->GetBrainComponent()->RestartLogic(); // AIController 다시 재가동 (BT 재시작)
                }
            }, 4.0f, false);
    }
 
.
.
.
 
}
cs

대미지가 들어오는 상황에도 IsGroggy 변수를 넣어줘서, 한 번 Groggy 상태가 되었을 때 중복 실행되는 것을 막아줌

 

위 isGroggy와 마찬가지로 isDead 변수 확인 추가로 사망 애니메이션 반복 재생 방지

 

* Damage 관리를 Player BP에서 Collision 종류 별로 관리 -> 만들기는 간편하나, 판정이나 유지 보수가 불편

추후 제작 시 공부를 통해 코드로만 작성하는 것이 바람직할 것 같음

 

* 한 번의 공격에 여러 대상이 맞지 않는 현상 수정해야함; 문제 원인 Do Once 노드

 

* Ultimate 사용 후 Set Movement가 Walking으로 바뀌기 전에 다른 행동 시 Walking 으로 변경되지 않아 이동되지 않는 현상 수정