From 7127c9e729bd7fef3f19cb32fbbc809226aa2881 Mon Sep 17 00:00:00 2001 From: Steve Streeting Date: Thu, 14 Mar 2024 16:36:24 +0000 Subject: [PATCH] Add ability to VLOG what spring arm is occluded from --- .../Private/StevesSpringArmComponent.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Source/StevesUEHelpers/Private/StevesSpringArmComponent.cpp b/Source/StevesUEHelpers/Private/StevesSpringArmComponent.cpp index 0af87f8..e570529 100644 --- a/Source/StevesUEHelpers/Private/StevesSpringArmComponent.cpp +++ b/Source/StevesUEHelpers/Private/StevesSpringArmComponent.cpp @@ -1,6 +1,10 @@  #include "StevesSpringArmComponent.h" +#include "StevesUEHelpers.h" + +// Set this to 1 to VLOG where camera is being occluded from +#define ENABLE_VLOG_CAMERA_OCCLUSION 0 UStevesSpringArmComponent::UStevesSpringArmComponent() { @@ -12,6 +16,24 @@ FVector UStevesSpringArmComponent::BlendLocations(const FVector& DesiredArmLocat bool bHitSomething, float DeltaTime) { + +#if ENABLE_VLOG_CAMERA_OCCLUSION +#if ENABLE_VISUAL_LOG + if (bHitSomething) + { + FVector NewDesiredLoc = PreviousDesiredLoc - PreviousDesiredRot.Vector() * TargetArmLength; + // Add socket offset in local space + NewDesiredLoc += FRotationMatrix(PreviousDesiredRot).TransformVector(SocketOffset); + FCollisionQueryParams QueryParams(SCENE_QUERY_STAT(SpringArm), false, GetOwner()); + FHitResult Result; + if (GetWorld()->SweepSingleByChannel(Result, PreviousArmOrigin, NewDesiredLoc, FQuat::Identity, ProbeChannel, FCollisionShape::MakeSphere(ProbeSize), QueryParams)) + { + UE_VLOG_ARROW(this, LogStevesUEHelpers, Log, PreviousArmOrigin, Result.Location, FColor::Cyan, TEXT("")); + UE_VLOG_LOCATION(this, LogStevesUEHelpers, Log, Result.Location, ProbeSize, FColor::Cyan, TEXT("%s"), *Result.GetActor()->GetActorNameOrLabel()); + } + } +#endif +#endif // These locations are in world space, we only want to blend the arm length, not the rest const FVector Base = Super::BlendLocations(DesiredArmLocation, TraceHitLocation, bHitSomething, DeltaTime);