Reader small image

You're reading from  Game Development Projects with Unreal Engine

Product typeBook
Published inNov 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781800209220
Edition1st Edition
Languages
Tools
Right arrow
Authors (4):
Hammad Fozi
Hammad Fozi
author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

Gonçalo Marques
Gonçalo Marques
author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

David Pereira
David Pereira
author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

Devin Sherry
Devin Sherry
author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry

View More author details
Right arrow

11. Blend Spaces 1D, Key Bindings, and State Machines

Overview

This chapter begins by creating the Blend Space asset needed to allow movement animation blending from idle to walking, and finally to running, based on the speed of the player character. We will then implement new key mappings and use those mappings in C++ to code gameplay functionality for the player character, like sprinting. Lastly, we will create a new animation state machine within our character animation blueprint so that the player animations can smoothly transition between movement and jumping.

By the end of this chapter, you will have the SuperSideScroller player character animating correctly when moving around the environment and moving in a way that feels best for the game. This means that the player will support an idle, walking, and sprinting animation, while also supporting the animations needed for jumping.

Introduction

In the previous chapter, we had a high-level look at animation and the development of the game design for your SuperSideScroller project. You were provided with just the beginning steps in the development of the project itself. You also prepared the player' characters' animation blueprint, character blueprint, and imported all of the required skeletal and animation assets.

At this point, the character can move around the level, but is stuck in the T-Pose and does not animate at all. This can be fixed by creating a new Blend Space for the player character, which will be done in the very first exercise of this chapter. Once the Blend Space is complete, you will implement this in the character animation blueprint in order for the character to animate while moving.

In this chapter, you will be working with many new functions, asset types, and variables in order to achieve the desired movement of the player character. Some of these include the Try Get Pawn...

Blend Spaces

Blend Spaces, as the name suggests, allow you to blend between multiple animations based on one or more conditions. Blend Spaces are used in different types of video games, but, more often than not, in games where the player can view the entire character. Blend spaces are not usually used when the player can only see the character arms, such as in the First-Person template project provided in Unreal Engine 4, as shown below:

Figure 11.1: The first-person perspective of the default character in the First-Person project template in Unreal Engine 4.

It is more common in third-person games where there is a need to use Blend Spaces to smoothly blend movement-based animations of the character. A good example is the Third-Person template project provided in Unreal Engine 4, as shown below:

Figure 11.2: The third-person perspective of the default character, in the First-Person project template in Unreal Engine 4

Blend Spaces allow...

Main Character Animation Blueprint

With the animations added to the Blend Space, you should be able to walk around and see those animations at work, right? Well, no. If you select Play-In-Editor, you will notice that the main character is still moving in the T-Pose. The reason is because you aren't yet telling the animation blueprint to use our Blend Space asset, which you will do later in this chapter.

Animation Blueprints

Before jumping into using the animation blueprint you created in the last chapter, let's briefly discuss what this type of blueprint is, and what its main function is. An animation blueprint is a type of blueprint that allows you to control the animation of a skeleton and skeletal mesh, in this instance, the player character skeleton and mesh you imported in the last chapter.

An animation blueprint is broken into two main graphs:

  • Event Graph
  • Anim Graph

The Event Graph works as in a normal blueprint where you can use events...

Velocity Vectors

Before moving on to the next step, let's explain what you are doing when you get the velocity of the character and promote the vector length of that vector to the Speed variable.

What is velocity? Velocity is a vector that has a given magnitude and a direction. To think about it another way, a vector can be drawn like an arrow. The length of the arrow represents the magnitude, or strength, and the direction of the arrowhead represents the direction. So, if you want to know how fast the player character is moving, you will want to get the length of that vector. That is exactly what you are doing when we use the GetVelocity function and the VectorLength function on the returned velocity vector; you are getting the value of the Speed variable of our character. That is why you store that value in a variable and use it to control the Blend Space, as shown in the following figure, which is an example of vectors. Where one has a positive (right) direction with...

Input Bindings

Every game requires input from the player, whether it is the keys on a keyboard such as W, A, S, and D for moving the player character, or the thumb sticks on a controller; this is what makes video games an interactive experience. Unreal Engine 4 allows us to map keyboard, mouse, gamepad, and other types of controls to labeled actions or axes that you can then reference in Blueprint or C++ to allow character or gameplay functionality to occur. It is important to point out that each unique action or axis mapping can have one or more key bindings, and that the same key binding can be used for multiple mappings. Input bindings are saved into an initialization file called DefaultInput.ini and can be found in the Config folder of your project directory.

Note

Input bindings can be edited directly from the DefaultInput.ini file or through Project Settings in the editor itself; the latter being more easily accessible and less error-prone when editing.

Let&apos...

Animation State Machines

Now, let's get to know what state machines are in the context of Unreal Engine 4 and in animation. State machines are a means of categorizing an animation, or sets of animations, into their own state. A state can be thought of as a condition that the player character is in at a specific time. Is the player currently walking? Is the player jumping? In many third-person games such as The Last of Us, this is the separation of movement, jumping, crouching, and climbing animations into their own state. Each state is then accessible when certain conditions are met while the game is played. Conditions can include whether the player is jumping, the speed of the player character, and whether or not the player is in the crouched state. The job of the state machine is to transition between each state using logical decisions called Transition Rules. When you create multiple states with multiple transition rules that intertwine with one another, the state machine begins...

Summary

With the player movement Blend Space created and the player character animation blueprint using a state machine to transition from movement to jumping, you are ready to move on to the next chapter, where you will prepare the required animation slot, animation montage, and update the animation blueprint for the throw animation that will use only the upper body of the character.

From the exercises and activities in this chapter, you learned how to create a 1D Blend Space that allows the smooth blending of movement-based animations such as idling, walking, and running using the speed of the player character to control the blending of animations.

Additionally, you learned how to integrate new key bindings into the project settings and bind those keys in C++ to enable character gameplay mechanics such as sprinting and throwing.

Lastly, you learned how to implement your very own animation state machine within the character animation blueprint in order for the player to...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Game Development Projects with Unreal Engine
Published in: Nov 2020Publisher: PacktISBN-13: 9781800209220
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (4)

author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry