Like I said last week, some people showed interest in knowing how Kerfuffight worked behind the scenes. Especially since it's using Blueprint (Unreal 4's visual scripting tool) entirely. Well, I'm happy to oblige!
(To see each picture in their original size, you can right-click on them and select "open in a new tab".)
This is the script that handles player movement in the game for both keyboard and gamepad (there's another script that handles sorting keyboard and gamepad inputs but that'll be topic for another day). It's stored on the player controller which, like its name suggests, controls the player.
Like I established previously, this script starts by receiving the value of the keyboard's or gamepad's X and Y axes. It then stores each in an appropriately named variable.
Before going any further, the script is stopped by a wall of conditions. If any of these conditions fail, the player won't be able to move.
(You can also notice there's an event to store the current mouse location, that's not relevant to this script).
As you can see here, if the condition check doesn't give out "true", it will skip the movement node. But if it does, that's when movement happens. First, the script checks if the owned player (the controlled player) is valid. If it is, it adds movement input to it in a given direction. It gets that direction from getting the rotation of the controller.
To help you visualize, the controller is usually aligned with the camera.
After that, the script gets both the forward and right vector from that rotation (think of them as directions). It then multiplies both vectors by the movement axes and adds both results. This gives us the direction in which we want to move the player aligned with the controller.
That direction is then stored in a variable.
The last part of the script is not too complicated. It's mostly storing information in variables to use in other scripts. The "Add Total Movement" function is used to store how many units a player travelled in a match (the "Runner" and "Statue" awards are given based on that information). The script then saves in another variable if the player is moving or not.
The last variable is a bit more interesting. In some cases, it's useful to know what was the last direction the player went in. Especially when you want to execute a direction based action while the player is not moving. In Kerfuffight's case that would be when dashing, so you don't dash in no direction.
Anywho, that's all for the movement script Don't hesitate to let me know if you want me to keep writing about the various scripts that make Kerfuffight work or what you want to be covered next.
Until then, you can like Kerfuffight on Facebook, follow it on Twitter or join the Discord. Also, don't forget to head over to the game's Steam page if you want to buy Kerfuffight!
Have a great day!