From 011bfcf62a29c188fa3727653c723b971f415042 Mon Sep 17 00:00:00 2001 From: "j.foucher" Date: Tue, 31 Mar 2026 17:59:22 +0200 Subject: [PATCH] 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) --- .../Private/BT/PS_AI_Behavior_BTTask_FleeFrom.cpp | 8 ++++++++ .../Private/PS_AI_Behavior_AIController.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/BT/PS_AI_Behavior_BTTask_FleeFrom.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/BT/PS_AI_Behavior_BTTask_FleeFrom.cpp index 13b7164..d9e6b62 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/BT/PS_AI_Behavior_BTTask_FleeFrom.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/BT/PS_AI_Behavior_BTTask_FleeFrom.cpp @@ -2,6 +2,7 @@ #include "BT/PS_AI_Behavior_BTTask_FleeFrom.h" #include "PS_AI_Behavior_AIController.h" +#include "PS_AI_Behavior_Interface.h" #include "PS_AI_Behavior_Definitions.h" #include "BehaviorTree/BlackboardComponent.h" #include "NavigationSystem.h" @@ -20,6 +21,13 @@ EBTNodeResult::Type UPS_AI_Behavior_BTTask_FleeFrom::ExecuteTask( APS_AI_Behavior_AIController* AIC = Cast(OwnerComp.GetAIOwner()); 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()) + { + IPS_AI_Behavior_Interface::Execute_SetBehaviorCrouch(FleePawn, false); + } + UBlackboardComponent* BB = OwnerComp.GetBlackboardComponent(); if (!BB) return EBTNodeResult::Failed; diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/PS_AI_Behavior_AIController.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/PS_AI_Behavior_AIController.cpp index e8441d5..b9130c2 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/PS_AI_Behavior_AIController.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_Behavior/Source/PS_AI_Behavior/Private/PS_AI_Behavior_AIController.cpp @@ -237,6 +237,18 @@ void APS_AI_Behavior_AIController::SetBehaviorState(EPS_AI_Behavior_State NewSta } Blackboard->SetValueAsEnum(PS_AI_Behavior_BB::State, NewVal); + // ─── Leaving cover/hiding: stand up ───────────────────────── + const EPS_AI_Behavior_State OldState = static_cast(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()) + { + IPS_AI_Behavior_Interface::Execute_SetBehaviorCrouch(MyPawn, false); + } + } + // ─── Dead: shut down all AI systems ───────────────────────── if (NewState == EPS_AI_Behavior_State::Dead) {