x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AI Perception - Custom Sight Strength In C++?

I've been researching this for days, anyone know how to allow for AI Perception's Sight to use a custom value for Strength rather than just "1" using C++? Would I need to set up the AISightTargetInterface in any way, if so, how?

Any help would be appreciated Mieszko!

alt text

Product Version: UE 4.19
Tags:
more ▼

asked Dec 03 '18 at 01:39 AM in C++ Programming

avatar image

Lewis James Fox
21 1 2 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

I found out how to do it! This works on Unreal Engine 4.19.2, this is the answer for anyone else with the same question.

Add this to your perceived pawn header file:

 #include "Runtime/AIModule/Classes/Perception/AISightTargetInterface.h" 

Make IAISightTargetInterface public in your class header file:

 class YOUR_GAME_API APawn: public ACharacter, public IAISightTargetInterface

Expose "CanBeSeenFrom" Function under public in your header file:

 public:
     // Sets default values for this character's properties
     APawn();
 
 virtual bool CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed, float& OutSightStrength, const AActor* IgnoreActor = NULL) const;

Then in your CPP file, add this:

 bool APawn::CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed, float& OutSightStrength, const AActor* IgnoreActor) const
 {
     static const FName NAME_AILineOfSight = FName(TEXT("TestPawnLineOfSight"));
 
     FHitResult HitResult;
     const bool bHit = GetWorld()->LineTraceSingleByObjectType(HitResult, ObserverLocation, GetActorLocation(), FCollisionObjectQueryParams(ECC_WorldStatic), FCollisionQueryParams(NAME_AILineOfSight, true, IgnoreActor));
 
         NumberOfLoSChecksPerformed++;
 
     // Add any other checks you want to perform here
     // ...
     
     if (bHit == false || (HitResult.Actor.IsValid() && HitResult.Actor->IsOwnedBy(this)))
     {
         OutSeenLocation = GetActorLocation();
         OutSightStrength = //YOUR CUSTOM VALUE GOES HERE;
     }
     OutSightStrength = 0;
     return false;
 }






more ▼

answered Dec 14 '18 at 01:50 PM

avatar image

Lewis James Fox
21 1 2 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question