Blueprints: Score-chan actor

A little technical blog post this week, as I talk through the creation of the Score-chan Actor BluePrint in Unreal Engine 4. Paper2D functionality in UE4 is not officially supported anymore and has a couple of quirks. However the Sprite and Flipbook Actor Blueprint classes are very useful and contain everything you need to quickly and easily create 2D character controllers.

When creating the Actor choose the PaperFlipbookActor preset.

Firstly, create a new BluePrint and select the PaperFlipbookActor class. It’ll auto-select when you type “flipbook” in the class search/filter field.

The character movement component has all the options you need.

Here you can see the basics of Score-chan’s Actor Blueprint. The capsule component is the root of it all and functions as the character’s collision as well (instead of sprite/flipbook collisions). There is also a little shadow sprite attached to the “Sprite” (which is actually a flipbook). There is a “buttonhelp” graphic which is a little speech balloon with the A button in it to prompt players to press A when she’s near an actionable object. There is a locator to spawn Gig near her, from where he’ll follow Score-chan wherever she walks. And finally, as part of the class default, there is a character movement component.

This character movement component handles a LOT of the heavy lifting when it comes to Score-chan’s movement in the game. There are a tonne of options but in the end I only use a few. As the camera of the game is more or less side-on (not top-down) her basic movement is set to “flying” and gravity is switched off. When you walk around the screen the actor is actually just floating wherever you move it, and the use of animated flipbooks give the illusion of her walking.

As we’re viewing the game “side on”, so to speak, Score-chan’s movement is set to “flying” and ignores gravity.

Even though movement is set to “flying” there is one super important setting under “Character movement: Walking” that requires attention. Even when flying the “Max Step Height” is used to let a character set up objects that are higher than itself. Say you’re making a game with a side-on staircase using step height will let your character automatically step up each step as opposed to getting stopped by collision boundaries. When flying this is used to let a character move around obstacles automatically by a margin. As Piczle Cross Adventure is treating most things at a pixel scale, not setting this parameter to 0 caused Score-chan to jump around the screen when she hit certain sized collision boxes.

The last moved direction is based on the left/right and up/down values of movement, with Score-chan having twice the number of directions as NPCs.

In the BluePrint of the actor I take the character’s velocity and break it down into its left/right and up/down axes. In my case that is X and Z respectively. I actually do a little manual check to make sure the script looks at the right quadrants for the most pleasing directional value.

As mentioned in a previous post, Score-chan can face in 8 different directions whereas most NPCs can only do 4. NPC are actor components too and are used in cutscenes, so they too need to automatically check for which direction to face when moved, for ease of cutscene creation.

For regular 3D characters you’d use behaviour trees to select which animations to run at what blending percentage based on what actions or speed the character is undergoing. Flipbook Actors do not have this, so directions and flipbook selections have to be manually scripted to handle that.

Simple add movement based on the axis value of the joystick.

For Score-chan, though, movement is an easy matter of taking the joystick’s directional value and applying it to a movement input. For NPC characters I simply move them with keyframes in Level Sequences, from where they derive their velocity and do all corresponding calculations based on that.

Setting the relevant flipbook for movement or standing idle based on the last moved direction.

After I check the actor’s velocity I set which flipbook to use. Here you can see how using the “select” node I can decide which flipbook to use depending on the character’s direction, or if the velocity of the character is 0, to use idle animations instead of walking animations.

You can see I’m currently applying specific flipbooks through parameters, but at some point I will create an array of flipbook animations and choose from there, for easy changes. Currently if I want to change one of the animations I can simply refer the corresponding parameter to a new flipbook (or adjust the existing flipbook), without having to change anything in this script.

As mentioned in a previous post, the sprite (flipbook) is set to rounded off values compared to the main capsule component for that pixel-perfect look.

And very finally, also mentioned in a previous post, I make sure the flipbook’s location is set to a rounded off coordinate based off the capsule component’s. In reality you’re controlling the capsule component, which glides around the world smoothly. Attached to this component is the Score-chan flipbook which will only be drawn at whole pixel coordinates.

The rest of the actor BluePrint is filled with other gamey stuff. Whether the player can control Score-chan can be toggled by calling an event. Whether the little balloon with the A button becomes visible is tied to overlap events with other actors. There is also a function, I have yet to expand on, that times how long Score-chan has been idle and can fire off different idle animations at certain times, or randomly. Plus the step counter, for the in-game pedometer, is also tied to the Score-chan Actor’s movement, which includes spawning a little dust cloud after an X number of steps.

To not bloat the Score-chan actor BluePrint I have also created a slimmed down copy that can be used in cutscenes and can have more flipbooks assigned to it through scripts, e.g. Score-chan waking up and looking around sleepily at the very start of the game is this non-interactive Score-chan actor which is replaced by the “real” Score-chan actor once the game hands the player control.

When the player is playing a puzzle, or a cleared puzzle object gets animated back into existence, the Score-chan actor is still there, ready and waiting, inactive until the player gets to control her again.

A well designed Actor BluePrint can take over so many of the hassles of character control. It’s nice to spend some time on a clean, functional BluePrint you can just “drop” into the world and have it all work nicely and predictably. Always research what existing BluePrint Classes UE4 has to offer before creating your own from scratch. You can save yourself a lot of time!

2 thoughts on “Blueprints: Score-chan actor

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s