Control with keyboard on MarbleRun

Hi everyone,
With this project, we control a board to make a ball rolling. At first, we used keyboard but we can’t hold the key to move the board (i.e. we had to press the key each time we wanted to rotate the board more). So the course made us change this to use the mouse value as an axis.
But I want to keep using the keyboard as a controller. So I want to take into account “key hold”: as long as the player hold the key, the board keep rotating.
I check several videos on youtube. I tried using the new input system (I’m on UE5.3). But it’s not working, when I run the game, the camera moves but not the board. Here are screenshots of what I did (I’m on an azerty keyboard, not a qwerty keyboard):



So, what I’m doing wrong?

The main reason why this is the case is because in Marble Run, the default pawn is being spawned into the world. And with it comes keyboard-based controls for movement. The reason you wouldn’t have noticed this before is because the keyboard controls in the level blueprint would override, or “consume”, the controls for the default pawn.

You’ll learn more about the default pawn and how to replace it in later lectures, but in keeping with the style of the current section here’s how you can disable the input for the default pawn and use the enhanced input system to get the controls you’d like. I’ll skip the creation of Input Actions and the Input Mapping Context since it looks like you got those nailed down already, awesome!

First things first, let’s make sure that the Input Mapping Context is enabled for our player controller’s Enhanced Input Local Player Subsystem by calling Add Mapping Context and supplying the mapping context in the node’s input. At the same time, we’ll get the pawn that’s being controlled by the player controller (which is the default pawn) and disable it’s input directly. Shown below:

(Note: I called my mapping context IMC_Main, you can call it whatever you want)

Next, we need to hook up our input to the movement of our maze. Thankfully, we can achieve this be only swapping out two nodes! Get the “Enhanced Action Values” nodes for your Input Actions, these act much like the GetMouseX and GetMouseY for the mouse-based movement in the course and can be subbed in without changing any other code! See below to see what I mean:

image
image
(Note: I gave my actions different names, that’s ok)

With these changes you’ll be able to use keyboard controls to move your maze and also stop the default pawn from moving, while modifying as little code from the section as possible.

It works perfectly! Thank you very much for your answer!

You’re welcome! Happy learning.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms