S1.19 Moving to where the click happened
Lesson Summary
In this lesson, we covered:
- Implementing character movement in Unreal Engine.
- Using the branch node to control execution flow.
- Adjusting movement inputs based on the direction of the mouse click.
What did we do?
✅ Updated for UE 5.4.1
Adding Movement Behavior only when the input is used
- Create a branch node by pressing B and clicking on the graph, or by dragging from the execution pin and typing and selecting Branch or If.
- Drag and drop the variable IsMoveActionEnabled on top of the Condition pin in the Branch node.
- Set up true and false execution paths.
- Test the execution with the branch node condition.
Show the mouse cursor on the screen to navigate the game easier
- Show the mouse by clicking on the Class Defaults button inside the PC_MyDungeonCrawler.
- Tick the Show Mouse Cursor checkbox.
Move in the direction of the mouse
- Add the node called Get Hit Result Under Cursor by Channel.
- Drag a wire from the Hit Result output pin and click on Break Hit Result.
- Expand the Break Hit Result, and from the Location output pin, drag a wire, type and click on Get Unit Direction (Vector).
- Make sure to connect the Location output pin to the To input pin of the Get Unit Direction (Vector) node.
- From the Get Controlled Pawn output pin called Return Value, drag a wire and add the Get Actor Location node.
- Connect the Get Actor Location output pin to the From input pin of the Get Unit Direction (Vector) node.
- Finally, connect the Return Value of the Get Unit Direction (Vector) node to the World Direction input pin of the Add Movement Input node.
Verify that the mouse click was valid
- From the Is Move Action Enabled variable, drag a wire and add the node AND Boolean.
- Connect the second input pin of the AND node with the Return Value pin of the Get Hit Result Under Cursor by Channel node.
- Connect the output node of the AND node to the input pin of the Branch node called Condition.
Code added in this video:
To copy the nodes in any graph, you can select them and press Ctrl + C or use the button below each graph. After copying the nodes, paste them (Ctrl + V) inside the editor's graph.
PC_MyDungeonCrawler
Hotkeys learned
In the Blueprint Editor
Create Branch Node: B + Click
Straighten node connections: Q (You need at least 2 nodes selected)
Comment box: C (if you have nodes selected, the comment box will be created around them)
Unreal Engine Terminology
Branch Node: A node that provides conditional branching in the execution flow, allowing for different execution paths based on a true or false condition.
Structure: In programming, a structure is a way of storing a collection of variables that are usually related.
In a structure created for a Bullet, we could hold a float variable called Weight, a text variable called Manufacturer, and a Mesh reference variable called 3D model.
Got Questions?
The UNF Games team is here for you! Members of our Private Community can ask questions about anything from this chapter by clicking on this link and creating a New Topic, where the Title starts with the Section and Video number.
Example title of new topic: [S3.12] Weird issue that I can’t solve
We know that nothing is perfect, so if the subtitles of this lesson are weird, or they don't make much sense, please let us know by making a post in this category in our community page.
Example title of new topic: [S3.12] Spanish - Weird translation issue that don’t make sense
If you have bought the course and haven't yet checked out our Private Teachable Community yet, just click on this link and see what you have been missing.
Ready to move on? Click "complete & continue" to proceed to the next lesson.