rythm_game_tutotrial

in Tutorials, UE4

Rhythm game using AudioAnalyzer

With this new tutorial series we are going to make a simple rhythm game using our AudioAnalyzer plugin for Unreal Engine 4. We are going to try to speak from both a theoretical and a practical point of view, resolving the problems that arise with this type of games

Design and main Level
User Interface widgets
Game Actor

In a rhythm game the player must interact with the game using their sense of rhythm and their ability to press buttons following an specific sequence. In most cases this interaction is done using the hands but we have games that uses devices created specifically for others parts such as the feet or even the entire body as well.

dancerush_stardom_machine
Dancerush Stardom machine

The game

youtube_video_rhythm

In our game the player will interact with a circular zone in the center of the screen.

game_preview

Beats travels from the left side to the right following a trajectory that pass through the circular zone. The player must try to push that zone when the beat is inside to increase the score. If he fail the score will suffer a penalty.

We are going to track only the bass frequency band to generate the beat spheres, in a complete game we can spawn multiple clickable zones and track different frequency bands, like low-mid and high-mid, and generate the beats of each different zone. This can become a great challenge to the player.

The UE4 project

We start creating a new empty blueprint project.

create_ue4_proejct

Our first step is to enable the AudioAnalyzer plugin on Editor > Plugins.

audioanalyzer_plugin

Now we can create the folder where the music will be stored. We need to include manually this folder to the directories list to package. On Packaging > Additional Non-asses Directories to Package we can add our new folder.

audio_folder

In this folder we can already put a sample audio file, we are going to choose a file that has the wanted frequency band very clear to be able to calibrate the game. After the calibration we can test the game with a real song.

audio_sample

We need to make the blueprint class of the Audio Analyzer Manager parent class. Right click in our Content folder > Blueprint Class > Search for AudioAnalyzerManager class > Select

audio_manager_class

This Blueprint instance will be the used to make our Audio Analyzer Manager objects

bp_audiomanager

The game controller will be an Actor object (this will be our BP_Game Blueprint class), the Level will only contain this actor and a camera.

game_structure

The BP_Game must contain the UI widgets and another Actor, the BP_Game_dealer, this class will spawn the beat Actor objects (BP_Game_dealer_beat).

We are going to create 2 audio manager objects (BP_AAManager), one to play the song and other to analyze it a few seconds ahead. To play other sounds like the menu sounds of FX effects we will use the unreal engine audio system.

aamanager_variables

We could create both variables directly in the BP_Game but instead we can use the GameInstance object to store this variables.

To create our game instance we can do right click on the content browser > Blueprint Class and search for GameInstance.

The game instance is not destroyed when changing levels, for this game with only one level we don’t need this class for it, but if you plain to have, for example, a level for the initial menu and different playable game levels this is the right method. Other advantage of this object is that can be access for any other blueprint class, this will be very useful.

So we are going to create a game instance with the 2 audio managers, the paths to the audio file, the score, and a reference to the BP_Game instance, this reference will be useful to use methods of our game actor from the UI widget without pass a reference directly, for example to pause and resume the playback of the audio.

gameinstance_variables
Our game instance variables

To access to this variables from any blueprint we need to obtain the game instance of the project and do cast to our game instance implementation.

gameinstance_cast
Obtaining score from our game instance

We are going to add a method to construct (Construct Object from Class) our audio managers, setting our game instance as the Outer class. This method will be called when the game start and link the life time of our managers to the life time of the game instance.

construct_aamanagers

When we have finished the creation of our game instance we need to select this in the project settings. Maps & Modes > Game Instance > Game Instance Class

gameinstance_project

We can save the Level and set it as the default map of the game, in this section too, before start to design the UI and the game actor.

default_maps

Now we can continue with the more interesting part of the game development

browser_content_1
Browser content at the end of this tutorial

Tutorial files:

github

UE4 Project

Part 2: User Interface widgets

Support this blog!

For the past year I've been dedicating more of my time to the creation of tutorials, mainly about game development. If you think these posts have either helped or inspired you, please consider supporting this blog. Thank you so much for your contribution!


Write a Comment

Comment

ten + one =