Unreal Engine Hack & Slash Tutorial [2024] Series | Part 9 | Training Dummy
Table of Contents
Introduction
This tutorial will guide you through the process of creating a training dummy in Unreal Engine as part of the Hack & Slash game development series. By the end of this tutorial, you will have a functional training dummy that players can interact with, allowing them to test their combat skills in your game. This guide is suitable for both Unreal Engine 4 and Unreal Engine 5 users.
Step 1: Setting Up the Training Dummy Actor
-
Create a New Actor:
- Open your Unreal Engine project.
- Right-click in the Content Browser and select Blueprint Class.
- Choose Actor as the parent class and name it
TrainingDummy.
-
Add Components:
- Open the
TrainingDummyblueprint. - In the Components panel, add a Static Mesh component.
- Select a suitable mesh for your dummy from the assets you have.
- Open the
-
Position the Dummy:
- Adjust the Static Mesh's position to ensure it is grounded and visible in the game world.
Step 2: Implementing Health System
-
Add Health Variable:
- In the
TrainingDummyblueprint, create a new variable namedHealth. - Set its type to Float and give it a default value (e.g., 100).
- In the
-
Create a Function to Take Damage:
- Create a new function called
TakeDamage. - Inside this function, subtract the damage amount from the
Healthvariable. - Use a Branch node to check if
Healthis less than or equal to zero. - If true, call the function to handle the dummy's destruction.
- Create a new function called
Step 3: Setting Up Input for Damage
-
Bind Input Action:
- Go to your project settings and navigate to Input.
- Add a new action mapping (e.g.,
Attack) and bind it to a key of your choice.
-
Detect Input in Character Blueprint:
- Open your character blueprint (where the player's attack logic is).
- Use the Input Action node for your
Attackaction. - Use a Line Trace to detect if you are aiming at the
TrainingDummy.
-
Apply Damage:
- If the line trace hits the
TrainingDummy, call theTakeDamagefunction on the dummy.
- If the line trace hits the
Step 4: Visual Feedback for Hits
-
Add Particle Effects:
- Download VFX assets from the Unreal Engine Marketplace to create hit effects.
- In the
TrainingDummyblueprint, add a Particle System component for the hit effect. - Trigger this effect in the
TakeDamagefunction whenever damage is applied.
-
Sound Effects:
- Import sound effects from the marketplace or other sources.
- Play a sound effect in the
TakeDamagefunction to provide audio feedback when the dummy is hit.
Conclusion
You have successfully created a training dummy in Unreal Engine that incorporates a health system, responds to player attacks, and provides visual and audio feedback. This foundational mechanic will enhance your hack and slash game's training experience.
Next steps could include refining the dummy's animations, adding more complex interactions, or integrating it into a larger gameplay loop. For any questions or further assistance, consider joining the Discord server linked in the video description. Happy developing!