C++ AI Perception | Make AI Look At Any Bone | AI Perception to Custom Sockets - UE4 C++ Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ค. 2021
  • This is a UE4 C++ tutorial video that shows you how to setup the "AIPerceptionComponent" in C++ and how to change the Sight Targets / View Targets for the perception system at runtime.
    #UE4 AI #AI Perception

ความคิดเห็น • 26

  • @letenebrae3164
    @letenebrae3164 2 ปีที่แล้ว

    Really great content, man

  • @mb.3d671
    @mb.3d671 3 ปีที่แล้ว

    Keep it up, ai is very hard but you made it simple

  • @MrVladiebaddie
    @MrVladiebaddie ปีที่แล้ว

    Kind of wish there was more C++ stuff for UE 5.0+. Thanks for the video it helped me out a ton even if it's a bit dated at this point.

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  ปีที่แล้ว

      Let me know if you need the updated code for ue5

    • @MrVladiebaddie
      @MrVladiebaddie ปีที่แล้ว

      @pranjalbhattacharjee5601 I'm good. I have it updated and running with no issues. It might break once I try to hook it up to a behavior tree.

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  ปีที่แล้ว

      @@MrVladiebaddie It should also work correctly with behavior trees.

  • @shannenmr
    @shannenmr 2 ปีที่แล้ว

    Thoughts on setting it up to trace to multiple bones and depending how many it see's the strength of the detection + increase the strength of the detection if it see's the same bones or increasing amount of bones for an extended period of time.
    (Like if it can only trace to the right hand the initial strength is very low but if it continues to see the hand the strength increases ... and if it starts seeing more like the right arm it increases the strength alot more)

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  2 ปีที่แล้ว

      This should be simple to implement but such a complex detection system would be difficult to convey to the player......I watched a gdc talk on the human ai of the last of us and there they said that initially they tried complex detection models but it was too confusing for the players and the final version just uses 3 line traces either to the chest or the head

    • @shannenmr
      @shannenmr 2 ปีที่แล้ว

      @@pranjalbhattacharjee5601 Similar to the discussion in the GDC Talk - Modeling AI Perception and Awareness in Splinter Cell: Blacklist
      I think my though boils down to if the AI can trace to your 1 bone because its showing through a slit or if its say you hand sticking out slightly you probably don't want it to react or at-least react quickly, but say you start exposing more then its seeing more + indicating there is movement which would cause "someone" to be more aware of it.
      In regards to conveying it to a player I would say most straight forward is Barks, so something like:
      See 1 bone bone the AI might say say "hey was there just movement over there / what's over there" and look in the direction + change their perception from being short range and broud to longer range and narrow.
      See 2 bones the AI says "hey you over there come out / who's that over there" and change perfection + maybe shoot a warning shot or continue to bark other similar things + maybe investigate.
      See 2 (one being major bone ) or more bones then full combat AI rules where it finds cover and calls for backup etc etc.

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  2 ปีที่แล้ว +2

      When the bot sees one bone the player might be behind cover but because of how the animations are setup one bone or may be a few bones are exposed.....if in this case the player is detected it would feel unfair to the player because the player was not given a better way to hide.....if your game has systems to give the player control over each and every bone then if the player gets detected it is because he/she did something wrong (ex: he had the option to fold his arm but he did not and got detected) otherwise such systems would only frustrate the player...... remember the bots are not there to behave realistically, they are there for the player's fun....so games always need to be player favouring and never make the player feel cheated..... emphasis on the word feel

  • @greengamerguy623
    @greengamerguy623 4 หลายเดือนก่อน

    I'm having a big problem with the Client not working the perception socket/bone can be changed but it doesn't attach please need help using 5.3

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  4 หลายเดือนก่อน

      I am not sure I understand what you are saying but for the "can be seen from" function to work, all he characters need to inherit from the same base class

  • @D.Mario03
    @D.Mario03 4 หลายเดือนก่อน

    Can you make it so that it will look at different bones by itself and not at runtime from the player input ?

  • @ashwinj9879
    @ashwinj9879 ปีที่แล้ว +1

    Does this work on ue5.1?

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  ปีที่แล้ว +3

      Use this for ue5.1
      // Custom View Target For AIPerception Component
      bool ACharacterBase::CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed,
      float& OutSightStrength, const AActor* IgnoreActor, const bool* bWasVisible, int32* UserData) const
      {
      static const FName NAME_AILineOfSight = FName(TEXT("TestPawnLineOfSight"));
      FHitResult HitResult;
      FVector SocketLocation = GetMesh()->GetSocketLocation(PerceptionTarget);
      const bool bHitSocket = GetWorld()->LineTraceSingleByObjectType(HitResult, ObserverLocation, SocketLocation,
      FCollisionObjectQueryParams(ECC_TO_BITFIELD
      (ECC_WorldStatic) | ECC_TO_BITFIELD(ECC_WorldDynamic)),
      FCollisionQueryParams(NAME_AILineOfSight, true,
      IgnoreActor));
      NumberOfLoSChecksPerformed++;
      if (bHitSocket == false || (HitResult.GetActor() && HitResult.GetActor()->IsOwnedBy(this)))
      {
      OutSeenLocation = SocketLocation;
      OutSightStrength = 1;
      return true;
      }
      const bool bHit = GetWorld()->LineTraceSingleByObjectType(HitResult, ObserverLocation, GetActorLocation(),
      FCollisionObjectQueryParams(ECC_TO_BITFIELD(ECC_WorldStatic) |
      ECC_TO_BITFIELD(ECC_WorldDynamic)), FCollisionQueryParams
      (NAME_AILineOfSight, true, IgnoreActor));
      NumberOfLoSChecksPerformed++;
      if (bHit == false || (HitResult.GetActor() && HitResult.GetActor()->IsOwnedBy(this)))
      {
      OutSeenLocation = GetActorLocation();
      OutSightStrength = 1;
      return true;
      }
      OutSightStrength = 0;
      return false;
      }

  • @creygelz
    @creygelz ปีที่แล้ว

    Thanks a lot for this! Although it only works if you use the same BaseCharacter for the AI and the Player. I'm forced to have different BaseCharacters for each. Is there a way to make that work? Been trying now for about 6h without success. Thanks a lot in advance for a response!

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  ปีที่แล้ว +1

      Well there are no good reasons for having different base characters for the player and the ai but if you must do it then put the "can be seen from" function in the parent class for the player

    • @creygelz
      @creygelz ปีที่แล้ว +1

      @@pranjalbhattacharjee5601 Thanks Pranjal! I already tried that. I might give it another go today. Could be a cpp plugin for the PlayerCharacter that acts as a child and is throwing off things. I'll comment if I succeeded. Thanks again.

  • @DavidRicardo97
    @DavidRicardo97 ปีที่แล้ว

    This looks a great tutorial but Perception is not running here.
    Perhaps i did some mistake or the content is outdated.
    Thank you anyway for sharing!

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  ปีที่แล้ว +1

      Use this for ue5.1
      // Custom View Target For AIPerception Component
      bool ACharacterBase::CanBeSeenFrom(const FVector& ObserverLocation, FVector& OutSeenLocation, int32& NumberOfLoSChecksPerformed,
      float& OutSightStrength, const AActor* IgnoreActor, const bool* bWasVisible, int32* UserData) const
      {
      static const FName NAME_AILineOfSight = FName(TEXT("TestPawnLineOfSight"));
      FHitResult HitResult;
      FVector SocketLocation = GetMesh()->GetSocketLocation(PerceptionTarget);
      const bool bHitSocket = GetWorld()->LineTraceSingleByObjectType(HitResult, ObserverLocation, SocketLocation,
      FCollisionObjectQueryParams(ECC_TO_BITFIELD
      (ECC_WorldStatic) | ECC_TO_BITFIELD(ECC_WorldDynamic)),
      FCollisionQueryParams(NAME_AILineOfSight, true,
      IgnoreActor));
      NumberOfLoSChecksPerformed++;
      if (bHitSocket == false || (HitResult.GetActor() && HitResult.GetActor()->IsOwnedBy(this)))
      {
      OutSeenLocation = SocketLocation;
      OutSightStrength = 1;
      return true;
      }
      const bool bHit = GetWorld()->LineTraceSingleByObjectType(HitResult, ObserverLocation, GetActorLocation(),
      FCollisionObjectQueryParams(ECC_TO_BITFIELD(ECC_WorldStatic) |
      ECC_TO_BITFIELD(ECC_WorldDynamic)), FCollisionQueryParams
      (NAME_AILineOfSight, true, IgnoreActor));
      NumberOfLoSChecksPerformed++;
      if (bHit == false || (HitResult.GetActor() && HitResult.GetActor()->IsOwnedBy(this)))
      {
      OutSeenLocation = GetActorLocation();
      OutSightStrength = 1;
      return true;
      }
      OutSightStrength = 0;
      return false;
      }

    • @DavidRicardo97
      @DavidRicardo97 ปีที่แล้ว

      @@pranjalbhattacharjee5601 I'm using 4.27.
      My AIControllerBase is running BeginPlay but isn't running OnPossess Event, for some reason.

    • @DavidRicardo97
      @DavidRicardo97 ปีที่แล้ว +1

      Ok, I've found the bug and it's working. Thank you!

    • @pranjalbhattacharjee5601
      @pranjalbhattacharjee5601  ปีที่แล้ว

      @@DavidRicardo97 do you have a blueprint version of the on possess event....??....if so call the parent function first before the blueprint logic