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.
Create the AI Character:
Blueprints
folder in your project.Blueprint Class
, then choose Character
. Name this blueprint BP_Neighbor
.BP_Neighbor
and set the mesh to the Neighbor Low Poly
mesh.ABP_Neighbor
animation blueprint to your character. Adjust the character's rotation to face the correct direction.Define AI States:
Blueprints
folder, right-click and create a new Enumeration called E_NeighborState
.BP_Neighbor
blueprint, create a variable called CurrentState
of type E_NeighborState
. Also, create a Boolean variable CanSeePlayer
.Create Behavior Trees and Blackboard:
Behavior
.BT_Neighbor_Idle
BT_Neighbor_Hunt
BT_Neighbor_Offline
BT_Neighbor_Attack
BB_Neighbor
to store variables.Setting AI States:
BP_Neighbor
, create a function called SetState
.NewState
of type E_NeighborState
.NewState
is not equal to CurrentState
before executing further logic.Select
node to run the appropriate Behavior Tree based on the state.Managing Speed Based on State:
AI Perception Component:
AI Perception
component named SightComponent
to the AI character and configure its peripheral vision.Chasing the Player:
Target Perception Updated
event to determine when the AI senses the player.CanSeePlayer
variable based on whether the AI successfully senses the player.Behavior on Seen Player:
Attack
if it can see the player.Attack
mode and handle the stopping of the music when the state changes.Catching the Player:
CatchBox
to detect when the AI is close enough to catch the player.CatchPlayer
function to handle logic when the player is caught:Resetting the Game:
AI Losing the Player:
Attack
to Hunt
after a certain period if it cannot see the player.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: AI, Unreal Engine 4, Chase, Catch, BP_Neighbor, Behavior Trees, E_NeighborState, AI Perception, State Management
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.
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.