Create Immersive AI Characters with Root Motion in Unreal Engine

Create Immersive AI Characters with Root Motion in Unreal Engine

Table of Contents

  1. Introduction
  2. Creating an AI Character with Root Motion
  3. Walking to the Player
  4. Turning to the Player
  5. Walking Backwards when the Player Gets Close
  6. Attacking the Player
  7. Walking to Attack
  8. Avoiding Other Characters in the Scene
  9. testing the AI Character
  10. Conclusion

Introduction

In this Tutorial, we will be creating an AI character that can move using root motion. We will cover various behaviors such as walking to the player, standing in place, turning to face the player, walking backwards when the player gets close, attacking the player, and avoiding other characters in the scene. Let's get started!


Creating an AI Character with Root Motion

To begin, we need to create a blueprint class for our AI character. Right-click in the anime folder and select "Create Blueprint Class". Name the blueprint "Character_BP_Anime". For the mesh, choose "SK_Mannequin" as a simple example. Set the Z location to -90, and the rotation to -90. Right-click and create an animation blueprint named "ABP_Enemy" using the "SK_Mannequin" skeleton.

Walking to the Player

To make our AI character walk towards the player, we need to set up the necessary animations and logic. First, we'll create a custom event called "Walk" in our character blueprint. Add a new float variable named "Forward Speed" and another variable named "Side Speed". Set the "Forward Speed" to the desired speed for walking and the "Side Speed" to 0. Connect these variables to the "Set Mode Speed" function in the animation blueprint.

Turning to the Player

Next, we'll add the functionality for the AI character to turn and face the player. Create a custom event called "Turn to Player Rotation" and add an output variable named "Arrived at Target" with a Boolean data type. In the event graph, check if the AI character has arrived at the target. If not, set the actor rotation to face the player.

Walking Backwards when the Player Gets Close

To make the AI character walk backwards when the player gets close, we need to implement a logic that detects the player's proximity. Create a function called "Find Distance" that calculates the distance between the AI character and the player. If the distance is less than a predefined value, set the "Is Near" boolean to true.

Attacking the Player

Now, let's implement the attack behavior for our AI character. We can create a custom event called "Attack" that triggers the attacking animation montage. Play the animation montage for the attack and set the collision properties to block visibility. This will allow the attack animation to interact with the player.

Walking to Attack

To make the AI character walk towards the player while attacking, we need to combine the walking and attacking behaviors. In the "Walk" function, set the forward and side speeds to appropriate values for attacking. The AI character will then walk towards the player while performing the attack animation.

Avoiding Other Characters in the Scene

If we have multiple AI characters in the scene, we want to make sure they don't collide with each other. To implement this behavior, we can use collision detection and pathfinding. Create a new function called "Avoid Other Characters" that uses collision detection to find a path around other characters in the scene.

Testing the AI Character

Now that we have implemented all the necessary behaviors for our AI character, it's time to test it in the Game. Place the AI character in the scene and observe its movement and interactions with the player. Make sure to test different scenarios to ensure that the AI character behaves as expected.


Conclusion

In this tutorial, we have learned how to create an AI character with root motion and various behaviors such as walking to the player, turning to face the player, attacking the player, and avoiding other characters in the scene. By applying these techniques, you can create more immersive and interactive gameplay experiences. Thank you for following along, and feel free to leave any questions or comments below!


Highlights

  • Create an AI character with root motion
  • Implement walking, turning, and attacking behaviors
  • Avoid collisions with other characters in the scene
  • Test and optimize the AI character's behavior

FAQ

Q: Can the AI character be controlled by the player? A: No, the AI character is controlled by the game's AI system and follows predefined behaviors.

Q: Can the AI character be customized with different animations? A: Yes, you can swap out the animations and customize the AI character's movements to suit your game's needs.

Q: Can the AI character be used in multiplayer games? A: Yes, the AI character can be used in multiplayer games by syncing its behavior across all connected clients.

Q: Can the AI character navigate dynamically changing environments? A: Yes, the AI character can adapt to dynamically changing environments by using pathfinding algorithms to find the best route.

Q: Can the AI character be used in different game genres? A: Yes, the AI character can be used in various game genres such as action, adventure, RPG, and more.


Resources:

Most people like

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content