(likely user error) Godot's Tutorial code exhibiting unexpected behavior

Godot Version

Godot Engine v4.3.stable.official.77dcf97d8
Vulkan 1.3.271 - Forward Mobile - Using Device #0: NVIDIA - NVIDIA GeForce RTX 2060 SUPER

Question

I am reading the GODOT documentation and following getting started tutorial here Listening to player input — Godot Engine (stable) documentation in English

I think I am doing something wrong but I can’t seem to find what it is. I am asking for help to figure out where I’ve gone astray.

According to the tutorial, with this script I should expect the following behavior:

  • the sprite2d node responds to directional input left and right (pressing my left and right arrow keys) by turning left and right when those inputs are pressed.

Actual behavior:

  • the sprite2d node does not respond to directional input and instead rotates continuously

Tutorial code vs my code side by side.

expected behavior:
expected_behavior

actual behavior:
actual_behavior

Any assistance is appreciated.

If the code isn’t responding to key presses then it could be that the input map has not been set up.

if Input.is_action_pressed("ui_left"):
if Input.is_action_pressed("ui_right"):
if Input.is_action_pressed("ui_up"):

ui_left, ui_right, ui_up are input actions. They are found under Project/Project Settings/Input Map.
Click on Show Built In Actions and look at the list of input actions. If you don’t see those three actions then you must add them.
But they are usually there by default.
Are you pressing the arrow buttons? (You most likely are but I had to ask)
Click on the game window before trying the buttons. I noticed on 4.3 that I have to click on the game window as the editor keeps focus. (Not sure if that is a setting or what)

See Project Setting > Input Map and turn on Show Built-in Actions.
You can see “ui_left”, “ui_right” and “ui_up”, click on plus in right side of actions (for example “ui_left”) and select Keyboard Keys and OK.
Now in “ui_left” you have a Keyboard Key, click on edit (pencil in right side) and click on your keyboard left key and select OK.
Do it for 3 Actions (“ui_left”, “ui_right” and “ui_up”) and try.

What I tried:
I went into Project/Project Settings/Input Map.
I clicked on Show Built In Actions.
The “ui_left”, “ui_right”, and “ui_up” were set already, but I set them again for good measure.
I made sure I clicked on the game window before trying the buttons.

No change in behavior unfortunately. I noticed that since the sprite was spinning from the beginning - it looks like the “if” statement on line 11 is returning true at all times. The editor/engine believes that my right input is always pressed (it’s not). I have taken a screenshot to demonstrate:

According to this situation, maybe the problem is with your keyboard or the engine has a problem in receiving the keys, because this problem is not reasonable at all! But I have some ideas:

  1. Restart your engine
  2. Select other key: use a for left, d for right and w for up
  3. Delete other events: only use Keyboard Keys and remove Joypad events
1 Like

I noticed that this appears to be isolated to the right input. If I comment it out the other inputs behave as expected.

right_input_commented_out

Behavior persists after restarting the engine.
Reconfiguring the input button for ui_right results in no change in behavior

Deleting other events: only use Keyboard keys and remove Joypad events
SUCCESS.

actual behavior is in line with expected behavior.
This is the working configuration:

working_config

Marking your answer as solution. Thank you for your help!

1 Like

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