diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp index b6ae517..1344381 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_InteractionComponent.cpp @@ -198,6 +198,12 @@ void UPS_AI_ConvAgent_InteractionComponent::SetSelectedAgent(UPS_AI_ConvAgent_El if (bAutoManageListening) { OldAgent->StopListening(); + + // Disable body tracking — eyes+head will return to neutral via posture detach. + if (UPS_AI_ConvAgent_PostureComponent* Posture = FindPostureOnAgent(OldAgent)) + { + Posture->bEnableBodyTracking = false; + } } // ── Posture: detach ────────────────────────────────────────────── @@ -244,6 +250,12 @@ void UPS_AI_ConvAgent_InteractionComponent::SetSelectedAgent(UPS_AI_ConvAgent_El if (bAutoManageListening) { NewAgent->StartListening(); + + // Now that we're talking, enable full body tracking. + if (UPS_AI_ConvAgent_PostureComponent* Posture = FindPostureOnAgent(NewAgent)) + { + Posture->bEnableBodyTracking = true; + } } // ── Posture: attach ────────────────────────────────────────────── @@ -345,10 +357,12 @@ void UPS_AI_ConvAgent_InteractionComponent::AttachPostureTarget( if (UPS_AI_ConvAgent_PostureComponent* Posture = FindPostureOnAgent(AgentPtr)) { Posture->TargetActor = GetOwner(); + // Eyes+head only at first — body tracking is enabled when listening starts. + Posture->bEnableBodyTracking = false; if (bDebug) { - UE_LOG(LogPS_AI_ConvAgent_Select, Log, TEXT("Posture attached: %s -> %s"), + UE_LOG(LogPS_AI_ConvAgent_Select, Log, TEXT("Posture attached (eyes+head only): %s -> %s"), AgentPtr->GetOwner() ? *AgentPtr->GetOwner()->GetName() : TEXT("(null)"), GetOwner() ? *GetOwner()->GetName() : TEXT("(null)")); } diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_PostureComponent.cpp b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_PostureComponent.cpp index 45ddd8c..d77343a 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_PostureComponent.cpp +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Private/PS_AI_ConvAgent_PostureComponent.cpp @@ -240,12 +240,16 @@ void UPS_AI_ConvAgent_PostureComponent::TickComponent( } // Body smoothly interpolates toward its persistent target - const float BodyDelta = FMath::FindDeltaAngleDegrees( - Owner->GetActorRotation().Yaw, TargetBodyWorldYaw); - if (FMath::Abs(BodyDelta) > 0.1f) + // (only when body tracking is enabled — otherwise only head+eyes move). + if (bEnableBodyTracking) { - const float BodyStep = FMath::FInterpTo(0.0f, BodyDelta, SafeDeltaTime, BodyInterpSpeed); - Owner->AddActorWorldRotation(FRotator(0.0f, BodyStep, 0.0f)); + const float BodyDelta = FMath::FindDeltaAngleDegrees( + Owner->GetActorRotation().Yaw, TargetBodyWorldYaw); + if (FMath::Abs(BodyDelta) > 0.1f) + { + const float BodyStep = FMath::FInterpTo(0.0f, BodyDelta, SafeDeltaTime, BodyInterpSpeed); + Owner->AddActorWorldRotation(FRotator(0.0f, BodyStep, 0.0f)); + } } // ── 3. Compute DeltaYaw after body interp ────────────────────────── @@ -274,7 +278,7 @@ void UPS_AI_ConvAgent_PostureComponent::TickComponent( BodyTargetFacing, TargetWorldYaw); bool bBodyOverflowed = false; - if (FMath::Abs(DeltaFromBodyTarget) > MaxHeadYaw + MaxEyeHorizontal) + if (bEnableBodyTracking && FMath::Abs(DeltaFromBodyTarget) > MaxHeadYaw + MaxEyeHorizontal) { // Body realigns to face target TargetBodyWorldYaw = TargetWorldYaw - MeshForwardYawOffset; diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_PostureComponent.h b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_PostureComponent.h index f7d9d8a..e5728d2 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_PostureComponent.h +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_PostureComponent.h @@ -73,6 +73,12 @@ public: meta = (ToolTip = "Target actor to look at.\nSet to null to return to neutral.")) TObjectPtr TargetActor; + /** When false, body rotation is frozen — only head and eyes track the target. + * Useful to have the agent notice the player (eyes+head) before fully engaging (body). */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PS AI ConvAgent|Posture", + meta = (ToolTip = "Enable body rotation toward the target.\nWhen false, only head and eyes track.")) + bool bEnableBodyTracking = true; + /** Offset from the target actor's origin to aim at. * Useful for actors without a skeleton (e.g. (0,0,160) for eye-level). */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PS AI ConvAgent|Posture",