Advertisement
Guest User

Untitled

a guest
Nov 7th, 2017
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. IN HEADER:
  2.     public:
  3.         //Override - Returns position/direction of eyes(it is an added socket to the head)
  4.             UFUNCTION(BlueprintCallable, Category = Actor)
  5.             virtual void GetActorEyesViewPoint( FVector& OutLocation, FRotator& OutRotation ) const;
  6.            
  7.         //Override - Are we seen?
  8.             virtual bool CanBeSeenFrom(
  9.                 const FVector& ObserverLocation,
  10.                 FVector& OutSeenLocation,
  11.                 int32& NumberOfLoSChecksPerformed,
  12.                 float& OutSightStrength,
  13.                 const AActor* IgnoreActor = NULL
  14.             ) const;
  15.  
  16. IN CPP:
  17.     //Override - Returns position/direction of eyes(it is an added socket to the head)
  18.     void AYourCharacterClass::GetActorEyesViewPoint( FVector& OutLocation, FRotator& OutRotation ) const
  19.     {
  20.         OutLocation = GetMesh()->GetSocketLocation("eye");
  21.         OutRotation = GetMesh()->GetSocketRotation("eye");
  22.     }
  23.    
  24.     //Tests if the Head,Shoulder,Hands,Pelvis and Feet are seen or not, if either is true, returns true.
  25.     bool AYourCharacterClass::CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed, float& OutSightStrength, const AActor* IgnoreActor) const
  26.     {
  27.         static const FName NAME_AILineOfSight = FName(TEXT("TestPawnLineOfSight"));
  28.      
  29.         FHitResult HitResult;
  30.      
  31.         TArray<FName> SocketsToCheck = {"head","upperarm_l","upperarm_r","hand_l","hand_r","pelvis","foot_l","foot_r"};
  32.         FString asd = FString::FromInt(SocketsToCheck.Num());
  33.         if(GEngine){
  34.             GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Yellow, asd);
  35.         }
  36.      
  37.         for (int i = 0; i < SocketsToCheck.Num(); i++)
  38.         {
  39.             FVector socketLocation = GetMesh()->GetSocketLocation(SocketsToCheck[i]);
  40.        
  41.             //DrawDebugLine(GetWorld(), TraceStart, TraceEnd, FColor::Red, false, 1.0f);
  42.             DrawDebugLine(GetWorld(), ObserverLocation, socketLocation, FColor::Red, false, -1.0f, 0.0f, 4.0f);
  43.  
  44.             const bool bHitSocket = GetWorld()->LineTraceSingleByObjectType(
  45.                 HitResult, ObserverLocation, socketLocation
  46.                 , FCollisionObjectQueryParams(ECC_TO_BITFIELD(ECC_WorldStatic) | ECC_TO_BITFIELD(ECC_WorldDynamic)) // << Changed this line
  47.                 , FCollisionQueryParams(NAME_AILineOfSight, true, IgnoreActor)
  48.             );
  49.      
  50.             NumberOfLoSChecksPerformed++;
  51.      
  52.             if (bHitSocket == false || (HitResult.Actor.IsValid() && HitResult.Actor->IsOwnedBy(this))) {
  53.                 OutSeenLocation = socketLocation;
  54.                 OutSightStrength = 1;
  55.      
  56.                 return true;
  57.             }
  58.         }
  59.      
  60.         OutSightStrength = 0;
  61.         return false;
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement