Updated observation logic

This commit is contained in:
koritsa
2026-05-30 15:35:59 +03:00
parent 26fb88bc90
commit e70b1d757c
9 changed files with 190 additions and 47 deletions
@@ -134,40 +134,63 @@ UAISense_Sight::EVisibilityResult ANakedDesireCharacter::CanBeSeenFrom(const FCa
FVector& OutSeenLocation, int32& OutNumberOfLoSChecksPerformed, int32& OutNumberOfAsyncLosCheckRequested,
float& OutSightStrength, int32* UserData, const FOnPendingVisibilityQueryProcessedDelegate* Delegate)
{
const FVector StartLocation = Context.ObserverLocation;
const FVector BoobsBoneLocation = GetMesh()->GetBoneLocation(FName(TEXT("boobs_root")));
const FVector PelvisBoneLocation = GetMesh()->GetBoneLocation(FName(TEXT("pelvis")));
OutNumberOfLoSChecksPerformed++;
FHitResult BoobsHitResult;
const bool BoobsHit = CheckSight(StartLocation, BoobsBoneLocation, BoobsHitResult, Context.IgnoreActor);
FHitResult PelvisHitResult;
const bool PelvisHit = CheckSight(StartLocation, PelvisBoneLocation, PelvisHitResult, Context.IgnoreActor);
bool bTopVisible = false;
bool bBottomVisible = false;
const float Exposure = ComputeObservedExposure(Context.ObserverLocation, Context.IgnoreActor, bTopVisible, bBottomVisible);
if ((!BoobsHit || BoobsHitResult.GetActor() == this) && ClothingManager->IsBodyPartExposed(EBodyPart::Boobs))
// An observer perceives the player only when a revealing body part is within their line of sight.
if (Exposure > 0.0f)
{
UE_LOG(LogTemp, Warning, TEXT("Boobs hit"));
OutSeenLocation = BoobsBoneLocation;
const bool bSeenTop = bTopVisible && RevealAmount(EBodyPart::Boobs) > 0.0f;
OutSeenLocation = GetMesh()->GetBoneLocation(FName(bSeenTop ? TEXT("boobs_root") : TEXT("pelvis")));
OutSightStrength = 1.0f;
return UAISense_Sight::EVisibilityResult::Visible;
}
if ((!PelvisHit || PelvisHitResult.GetActor() == this) &&
(ClothingManager->IsBodyPartExposed(EBodyPart::Ass) || ClothingManager->IsBodyPartExposed(EBodyPart::Genitals)))
{
UE_LOG(LogTemp, Warning, TEXT("Pelvis hit"));
OutSeenLocation = PelvisBoneLocation;
OutSightStrength = 1.0f;
return UAISense_Sight::EVisibilityResult::Visible;
}
UE_LOG(LogTemp, Warning, TEXT("Not visoble"));
return UAISense_Sight::EVisibilityResult::NotVisible;
}
float ANakedDesireCharacter::GetObservedExposureFrom(const FVector& ObserverLocation, const AActor* IgnoreActor)
{
bool bTopVisible = false;
bool bBottomVisible = false;
return ComputeObservedExposure(ObserverLocation, IgnoreActor, bTopVisible, bBottomVisible);
}
float ANakedDesireCharacter::ComputeObservedExposure(const FVector& ObserverLocation, const AActor* IgnoreActor,
bool& bOutTopVisible, bool& bOutBottomVisible)
{
const FVector BoobsBoneLocation = GetMesh()->GetBoneLocation(FName(TEXT("boobs_root")));
const FVector PelvisBoneLocation = GetMesh()->GetBoneLocation(FName(TEXT("pelvis")));
float Exposure = 0.0f;
// Top region -> Boobs. A region is "visible" when its LOS trace is unobstructed (or only hits self).
FHitResult TopHit;
bOutTopVisible = !CheckSight(ObserverLocation, BoobsBoneLocation, TopHit, IgnoreActor) || TopHit.GetActor() == this;
if (bOutTopVisible)
Exposure += RevealAmount(EBodyPart::Boobs);
// Bottom region (pelvis) -> Ass + Genitals; one trace gates both lower parts.
FHitResult BottomHit;
bOutBottomVisible = !CheckSight(ObserverLocation, PelvisBoneLocation, BottomHit, IgnoreActor) || BottomHit.GetActor() == this;
if (bOutBottomVisible)
{
Exposure += RevealAmount(EBodyPart::Ass);
Exposure += RevealAmount(EBodyPart::Genitals);
}
return Exposure;
}
float ANakedDesireCharacter::RevealAmount(const EBodyPart BodyPart)
{
const float Coverage = ClothingManager->GetEffectiveCoverage(BodyPart);
return Coverage < ObservationRevealThreshold ? (1.0f - Coverage) : 0.0f;
}
bool ANakedDesireCharacter::CheckSight(const FVector& StartLocation, const FVector& EndLocation, FHitResult& HitResult,
const AActor* IgnoreActor)
{