Add uncrouch on state change and flee: civilians stand up when leaving cover

- AIController: auto uncrouch when leaving Fleeing/TakingCover state
- FleeFrom: uncrouch at start of flee (civilian was still crouched from HidingSpot)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
j.foucher 2026-03-31 17:59:22 +02:00
parent 391a35ac2c
commit 011bfcf62a
2 changed files with 20 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "BT/PS_AI_Behavior_BTTask_FleeFrom.h" #include "BT/PS_AI_Behavior_BTTask_FleeFrom.h"
#include "PS_AI_Behavior_AIController.h" #include "PS_AI_Behavior_AIController.h"
#include "PS_AI_Behavior_Interface.h"
#include "PS_AI_Behavior_Definitions.h" #include "PS_AI_Behavior_Definitions.h"
#include "BehaviorTree/BlackboardComponent.h" #include "BehaviorTree/BlackboardComponent.h"
#include "NavigationSystem.h" #include "NavigationSystem.h"
@ -20,6 +21,13 @@ EBTNodeResult::Type UPS_AI_Behavior_BTTask_FleeFrom::ExecuteTask(
APS_AI_Behavior_AIController* AIC = Cast<APS_AI_Behavior_AIController>(OwnerComp.GetAIOwner()); APS_AI_Behavior_AIController* AIC = Cast<APS_AI_Behavior_AIController>(OwnerComp.GetAIOwner());
if (!AIC || !AIC->GetPawn()) return EBTNodeResult::Failed; if (!AIC || !AIC->GetPawn()) return EBTNodeResult::Failed;
// Stand up if crouching (e.g. was hiding at a cover point before fleeing)
APawn* FleePawn = AIC->GetPawn();
if (FleePawn->Implements<UPS_AI_Behavior_Interface>())
{
IPS_AI_Behavior_Interface::Execute_SetBehaviorCrouch(FleePawn, false);
}
UBlackboardComponent* BB = OwnerComp.GetBlackboardComponent(); UBlackboardComponent* BB = OwnerComp.GetBlackboardComponent();
if (!BB) return EBTNodeResult::Failed; if (!BB) return EBTNodeResult::Failed;

View File

@ -237,6 +237,18 @@ void APS_AI_Behavior_AIController::SetBehaviorState(EPS_AI_Behavior_State NewSta
} }
Blackboard->SetValueAsEnum(PS_AI_Behavior_BB::State, NewVal); Blackboard->SetValueAsEnum(PS_AI_Behavior_BB::State, NewVal);
// ─── Leaving cover/hiding: stand up ─────────────────────────
const EPS_AI_Behavior_State OldState = static_cast<EPS_AI_Behavior_State>(OldVal);
if ((OldState == EPS_AI_Behavior_State::Fleeing || OldState == EPS_AI_Behavior_State::TakingCover)
&& NewState != EPS_AI_Behavior_State::Fleeing && NewState != EPS_AI_Behavior_State::TakingCover)
{
APawn* MyPawn = GetPawn();
if (MyPawn && MyPawn->Implements<UPS_AI_Behavior_Interface>())
{
IPS_AI_Behavior_Interface::Execute_SetBehaviorCrouch(MyPawn, false);
}
}
// ─── Dead: shut down all AI systems ───────────────────────── // ─── Dead: shut down all AI systems ─────────────────────────
if (NewState == EPS_AI_Behavior_State::Dead) if (NewState == EPS_AI_Behavior_State::Dead)
{ {