Topview Logo
  • Create viral videos with
    GPT-4o + Ads library
    Use GPT-4o to edit video empowered by Youtube & Tiktok & Facebook ads library. Turns your links or media assets into viral videos in one click.
    Try it free
    gpt video

    Hello Neighbor UE4 AI Tutorial #1 | Chase and Catch (REMAKE)

    blog thumbnail

    Introduction

    In this tutorial, we will create an AI for the neighbor character in Unreal Engine 4, enabling it to chase and catch the player. We will cover the framework setup, state management, behavior trees, and AI perception components.

    Step 1: Setting Up the AI Framework

    1. Create the AI Character:

      • Navigate to the Blueprints folder in your project.
      • Right-click and select Blueprint Class, then choose Character. Name this blueprint BP_Neighbor.
      • Open BP_Neighbor and set the mesh to the Neighbor Low Poly mesh.
      • Assign the ABP_Neighbor animation blueprint to your character. Adjust the character's rotation to face the correct direction.
    2. Define AI States:

      • In the Blueprints folder, right-click and create a new Enumeration called E_NeighborState.
      • Define the following states:
        • Idle
        • Hunt
        • Offline
        • Attack
      • In the BP_Neighbor blueprint, create a variable called CurrentState of type E_NeighborState. Also, create a Boolean variable CanSeePlayer.
    3. Create Behavior Trees and Blackboard:

      • Create a new folder named Behavior.
      • Inside, create the following Behavior Trees:
        • BT_Neighbor_Idle
        • BT_Neighbor_Hunt
        • BT_Neighbor_Offline
        • BT_Neighbor_Attack
      • Create a Blackboard named BB_Neighbor to store variables.

    Step 2: Programming State Management

    1. Setting AI States:

      • In the BP_Neighbor, create a function called SetState.
      • Input a parameter NewState of type E_NeighborState.
      • Check if NewState is not equal to CurrentState before executing further logic.
      • Use a Select node to run the appropriate Behavior Tree based on the state.
    2. Managing Speed Based on State:

      • Set the Max Walk Speed for each state:
        • Idle: 100
        • Hunt: 300
        • Offline: 200
        • Attack: 600
    3. AI Perception Component:

      • Add an AI Perception component named SightComponent to the AI character and configure its peripheral vision.
      • Set detection settings to allow the AI to see the player.

    Step 3: Implementing Chase and Catch Logic

    1. Chasing the Player:

      • Use the Target Perception Updated event to determine when the AI senses the player.
      • Set the CanSeePlayer variable based on whether the AI successfully senses the player.
    2. Behavior on Seen Player:

      • In event ticking (or custom timer), branch off to set the AI's state to Attack if it can see the player.
      • Play chase music when in Attack mode and handle the stopping of the music when the state changes.
    3. Catching the Player:

      • Use a collision box named CatchBox to detect when the AI is close enough to catch the player.
      • Create a CatchPlayer function to handle logic when the player is caught:
        • Play a catch sound.
        • Set the player's input to disabled.
        • Play a choking animation.
    4. Resetting the Game:

      • After catching the player, fade the screen and reset both the AI and the player to specific locations.
      • Make sure to re-enable player controls and reset states post-catch.
    5. AI Losing the Player:

      • Implement logic to switch the AI from Attack to Hunt after a certain period if it cannot see the player.
      • Play Hunt music in Hunt state.

    This comprehensive setup establishes the foundation for our AI behavior in the Hello Neighbor remake, allowing the neighbor to chase and catch the player effectively.


    Keywords

    Keywords: AI, Unreal Engine 4, Chase, Catch, BP_Neighbor, Behavior Trees, E_NeighborState, AI Perception, State Management


    FAQ

    Q: What is the purpose of the E_NeighborState enumeration?
    A: It defines the different states that the AI can be in, such as Idle, Hunt, Offline, and Attack.

    Q: How does the AI perceive the player?
    A: The AI uses an AI Perception component with a sight configuration to detect when the player is within its peripheral vision.

    Q: How does the catch mechanic work?
    A: A collision box detects when the AI is close enough to the player, triggering a sequence that plays a catch sound, disables player input, and plays an animation.

    Q: Can I customize the AI's behavior further?
    A: Yes, the AI's parameters such as timing, speeds, and music can be easily adjusted in the blueprint settings to fit your game's requirements.

    Q: Does the AI reset properly when it catches the player?
    A: Yes, after a catch sequence, the AI and player are reset to predefined locations, allowing for continuous play without level restarts.

    One more thing

    In addition to the incredible tools mentioned above, for those looking to elevate their video creation process even further, Topview.ai stands out as a revolutionary online AI video editor.

    TopView.ai provides two powerful tools to help you make ads video in one click.

    Materials to Video: you can upload your raw footage or pictures, TopView.ai will edit video based on media you uploaded for you.

    Link to Video: you can paste an E-Commerce product link, TopView.ai will generate a video for you.

    You may also like