Blueprint Part 2

Hi everyone!

Looks like a lot of you liked last week article!

I only showed the movement blueprint last week, but if someone was to copy-paste that script in their project, they'd notice that their character would move around while always facing the same direction.

That's why this week I'm going to show you the blueprint script that handles what direction the player is facing.

(To see each picture in their original size, you can right-click on them and select "open in a new tab".)

This is the whole script that controls the player character rotation so it's always facing the direction that the player inputs.
It's triggered every frame and handles both mouse inputs and gamepad inputs.

Unlike the script I showed last week, this one is on the player character and not on the player controller. The reason for that is that it is also partly used by AIs. AIs have their own controller but they use the same character so some scripts are shared between both types of controllers via the player character.

Let's look at the first part of the script.

First, it needs to check if the game mode is valid. Since this part of the blueprint is executed every frame it has the chance to execute before the "Game Mode" variable is assigned. As you can see that variable is used a bit later in this blueprint and it would generate an error in case it was not valid at this point.

Next, we check if this character is controlled by an AI or player controller. If it's controlled by the former, we simply send back if the AI can rotate based on some conditions.

Speaking of these conditions, they also control if we want the player to be able to rotate or not. These conditions depend on what type of game you're making, but the first is probably one you'd end up adding to your project too. It will stop the player from rotating if no direction or movement inputs are given by the player.

If ever the condition returns false, we check if the mouse location is different than 0 (note that only the player using a mouse is going to be able to influence this variable). If it is, we then use that location and the current player location to determine which direction we want to face.

You might also have noticed here that the condition check will be true when we want the player to NOT be able to rotate.

We then enter part 2 of the script.

Here, the script chooses what rotation to give the player depending on what path it is on. 

Starting from the top, it will keep it's current rotation if the player can't rotate. The next two outcomes will only occur if the player can rotate. If it can rotate and "is looking" (a variable that checks if a direction input is given by the player). If it is then the player direction will be dependent on the cursor's position relative to the player's position and if it is not, the rotation will follow the direction of the current movement direction.

Anywho, that's all for the direction 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!