From 6c081e1207b378d730efe2b62eab908434882009 Mon Sep 17 00:00:00 2001 From: "j.foucher" Date: Fri, 27 Feb 2026 17:49:03 +0100 Subject: [PATCH] Fix: body keeps orientation on target loss, fix close-range selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PostureComponent: body no longer returns to original yaw when TargetActor is cleared — only head and eyes return to neutral. InteractionComponent: add AgentEyeLevelOffset (default 150cm) so the view cone check targets chest height instead of feet, preventing selection loss at close range. Co-Authored-By: Claude Opus 4.6 --- .../Private/PS_AI_ConvAgent_InteractionComponent.cpp | 2 +- .../Private/PS_AI_ConvAgent_PostureComponent.cpp | 11 ++--------- .../Public/PS_AI_ConvAgent_InteractionComponent.h | 8 ++++++++ 3 files changed, 11 insertions(+), 10 deletions(-) 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 8721c21..3b5ed4f 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 @@ -129,7 +129,7 @@ UPS_AI_ConvAgent_ElevenLabsComponent* UPS_AI_ConvAgent_InteractionComponent::Eva AActor* AgentActor = Agent->GetOwner(); if (!AgentActor) continue; - const FVector AgentLocation = AgentActor->GetActorLocation(); + const FVector AgentLocation = AgentActor->GetActorLocation() + FVector(0.0f, 0.0f, AgentEyeLevelOffset); const FVector ToAgent = AgentLocation - ViewLocation; const float DistSq = ToAgent.SizeSquared(); 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 4275b67..45ddd8c 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 @@ -337,15 +337,8 @@ void UPS_AI_ConvAgent_PostureComponent::TickComponent( { // ── No target: smoothly return to neutral ────────────────────────── - // Body: return to original facing via sticky target - TargetBodyWorldYaw = OriginalActorYaw - MeshForwardYawOffset; - const float NeutralDelta = FMath::FindDeltaAngleDegrees( - Owner->GetActorRotation().Yaw, TargetBodyWorldYaw); - if (FMath::Abs(NeutralDelta) > 0.1f) - { - const float NeutralStep = FMath::FInterpTo(0.0f, NeutralDelta, SafeDeltaTime, ReturnToNeutralSpeed); - Owner->AddActorWorldRotation(FRotator(0.0f, NeutralStep, 0.0f)); - } + // Body: keep current orientation — don't rotate back to original facing. + // The body stays wherever the last tracking left it; only head and eyes reset. // Head + Eyes: return to center TargetHeadYaw = 0.0f; diff --git a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_InteractionComponent.h b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_InteractionComponent.h index 5069dd8..adba675 100644 --- a/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_InteractionComponent.h +++ b/Unreal/PS_AI_Agent/Plugins/PS_AI_ConvAgent/Source/PS_AI_ConvAgent/Public/PS_AI_ConvAgent_InteractionComponent.h @@ -77,6 +77,14 @@ public: ToolTip = "Sticky cone half-angle for the current agent (degrees).\nMust be >= ViewConeHalfAngle for hysteresis to work.\n60 = agent stays selected until 120-degree total cone is exceeded.")) float SelectionStickyAngle = 60.0f; + /** Height offset (cm) added to the agent's origin for the view cone check. + * Agent origins are typically at foot level; this shifts the target point + * up to chest/head height so close-range look-at checks don't fail. */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PS AI ConvAgent|Interaction", + meta = (ClampMin = "0", + ToolTip = "Height offset (cm) above the agent origin for the view cone check.\nPrevents losing selection at close range because the camera looks above the agent's feet.\n150 = roughly chest height for a MetaHuman.")) + float AgentEyeLevelOffset = 150.0f; + /** When false, only distance matters for selection (no view cone check). * The closest agent within MaxInteractionDistance is always selected. */ UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PS AI ConvAgent|Interaction",