godot
godot copied to clipboard
Movement doesn't work as expected when mapping keys and axes to the same action
Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.
Godot version: 3.2.4.rc1.official
OS/device including version: Windows 10 (19042.746)
Issue description: When I plug in a PS4 controller, KinematicBody2D doesn't move properly while using the d-pad buttons or the keyboard. Same occurs if I use DS4Windows to emulate a Xbox 360 controller (XInput).
(!) Note The same code works fine in Godot v3.2.3.stable, both for the PS4 controller (with and without DS4Windows) and the keyboard.
func _physics_process(delta):
velocity = get_direction() * speed
velocity = move_and_slide(velocity)
func get_direction():
var dir: = Vector2.ZERO
dir.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
dir.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
dir = dir.normalized()
return dir
Steps to reproduce:
- Open and run the attached project with a PS4 controller connected.
- Move the rectangle on the screen using WASD or the arrow keys, then try to move it using the d-pad buttons.
- The node's movement shouldn't work properly, neither with the keyboard or the controller.
- Disconnect the controller and the rectangle will move without problems using the keyboard.
Repeat steps 1 and 2 in Godot v3.2.3.stable.official and the rectangle will move without problems.
Here you can see how the gamepad registers the buttons pressing without moving the rectangle, same for WASD and arrow keys.
Minimal reproduction project:
Possibly related to #44721.
I don't have access to a PS4 controller; so, to help with troubleshooting, please provide the output (which button number or numbers is reported to be pressed) for each direction of the D-Pad when running the Joypads demo under both 3.2.3-stable and 3.2.4.rc1.
Thanks @madmiraal
The button numbers for 3.2.3-stable and 3.2.4.rc1 are the same.
Let me know if I can help with something else.
@mapedorr I'm struggling to understand what the problem is and it's difficult to tell from the video what is happening vs what is expected. With the joystick connected, please complete the following table:
Expected | What it does in 3.2.3 | What it does in 3.2.4.rc1 | |
---|---|---|---|
Doing Nothing | Nothing | ||
W pressed | |||
A pressed | |||
S pressed | |||
D pressed | |||
D-pad Up | |||
D-pad Left | |||
D-pad Down | |||
D-pad Right |
@madmiraal Hi, sorry for the late response and for not making clear what's going on.
Expected | What it does in 3.2.3 | What it does in 3.2.4.rc1 | |
---|---|---|---|
Doing Nothing | Nothing | Nothing | Nothing |
W pressed | Character moves up continiously | Works as expected | Character moves up and suddenly stops moving |
A pressed | Character moves left continiously | Works as expected | Character moves left and suddenly stops moving |
S pressed | Character moves down continiously | Works as expected | Character moves down and suddenly stops moving |
D pressed | Character moves right continiously | Works as expected | Character moves right and suddenly stops moving |
D-pad Up | Character moves up continiously | Works as expected | Character moves up and suddenly stops moving |
D-pad Left | Character moves left continiously | Works as expected | Character moves left and suddenly stops moving |
D-pad Down | Character moves down continiously | Works as expected | Character moves down and suddenly stops moving |
D-pad Right | Character moves right continiously | Works as expected | Character moves right and suddenly stops moving |
Same occurs for diagonals (pressing two buttons at the same time).
@mapedorr Just to clarify: It's behaving as if you've released the button when you haven't, but you don't see that in the Joypads Demo?
@madmiraal Exactly \ (-^〇^-) /
I am having this issue as well, my player stops and goes when using d-pad inputs in 3.2.4-rc2 not registering the key presses consistently. <:(
This may be a duplicate of #43674 i.e. the action_strength
is being reset to zero by the joystick due to a lack of a functioning deadzone.
@mapedorr Does the problem go away if you remove the axis mappings from the Input Map move_*
mappings?
@robertarnborg Do you also have D-Pad and Joystick movements mapped to the same input actions?
Yes @madmiraal . The problem disappears if I remove the axis mappings. 😄
@madmiraal yes, I have them mapped them to same action, in this case movement and the input is checking action_strength.
Mapping multiple keys or a key and an axis to a single action is known to cause issues: see #30888 and #39287. #30890 updated the documentation for is_action_pressed()
to highlight this, but the same applies to get_action_strength()
, which is what is happening here. This particular scenario was less evident in 3.2.3, because small movements were been filtered out (which was causing #42876, and fixed with #43233 and backported to 3.2 with #43234) but as identified in #39287, it is a pre-existing problem that doesn't have an easy fix.
@bojidar-bg suggested, changing the behaviour of is_action_pressed()
to not release until all bound buttons are released. This could be extended to get_action_strength()
, by using, for example, the maximum of multiple buttons and axes.
I'll update my code to handle this. Thank you so much for your help @madmiraal .
@mapedorr @robertarnborg I've created a PR (#47599) that should fix this problem. However, I don't have a PS4 controller to test it with. Please test it for us.
This GDScript workaround might help: https://github.com/godotengine/godot/pull/30890#issuecomment-833173710
I have noticed this same behavior for v3.3.stable.mono.official
. Disabling all axis input actions and just using dpad input actions fixed the problem for me. I was using an XInput controller (XBox 360)
I'm using Godot 3.3.1.stable and this issue is happening still, even when I have a PS4 controller connected to the USB but turned off, only recharging. Godot recognizes it as a connected joystick and when I map both a Stick axis and a keyboard key to the same action, the input stops randomly when pressing a key.
I noticed that even with the PS4 Controller turned off, Windows recognizes it as an Audio Device.
"Remover dispositivo" = Remove device
Is there a way to ignore joystick inputs besides removing them from the input mapping?
Is there a way to ignore joystick inputs besides removing them from the input mapping?
There's currently no way to disable controller support entirely, but I suppose that will need to be added eventually (e.g. with a project setting and --no-gamepad
CLI argument).
Note that this current behavior also causes issues in configurations where your keyboard is configured to send both key and gamepad events. I use a Wooting two HE analog keyboard, with the analog profile configured to send both key presses and left stick analog movement on the arrow keys. This allows using the same profile for general desktop usage and games that make use of analog movement.
This analog profile works great in games like Trackmania (even if steering is both bound to arrow keys and gamepad axes in-game). Unfortunately, it doesn't work as expected in Godot since the key and gamepad input will "fight" each other if both are configured for the same input action.
Testing project: test_analog_and_digital_input.zip
The top (white) progress bar represents the input that accepts both digital and analog input (with both inputs being sent from the keyboard). The middle (yellow) progress bar represents gamepad input only (separate action). The bottom (cyan) progress bar represents keyboard input only (another separate action).
The default deadzone is used for all inputs.
Here, I'm slowly pressing the key then depressing it:
https://user-images.githubusercontent.com/180032/137774927-79d72c26-d7fe-44e9-9956-54cbd1b75b4b.mp4
Calling Input.set_use_accumulated_input(false)
in _ready()
doesn't resolve this issue.
I am having this issue, I have WASD and a PS4 Controller, left stick axis, controlling the same inputs, and because there is no deadzone cut off, but only deadzone to activate and make true, using WASD with even a PS4 controller plugged in leads too movement stopping and starting non stop, until the PS4 Axis is moved, then for some bizarre reason now the issue is gone, and there is no way to change this using GDscript.
Issue persists on v4.0.beta9.mono.official.e780dc332
. PS4 Controller joystick + keyboard. Input cuts out.
Godot 4.0 beta 10. Seeing the same issue with the Steam Deck controller when you have d-pad and joystick input mapped to the same action.
a very niche problem that can cause issues with having a PS4 controller plugged in and trying to switch from one to the other, IE if you have both WASD and mouse enabled and also a controller it will cause issues. This can be avoided by having a menu option to switch between settings, but alot of if not the majority of games now implement a way to switch fluidly between the 2 with out them affecting each other. Not sure what causes this interaction.
https://www.reddit.com/r/godot/comments/v9bizt/comment/ic4ik6x/
Potentially to solve this issue could the input mapping have like an event priority per suggestion of workaround in this reddit thread.
"I have found a solution that seems to work OK.. I capture only the D-pad input vector, however if that's Vector2.ZERO then I'll capture the analogue stick motion and use that. So the D-pad is the dominant one, and the analogue stick is the fall back. Only issue might arise in a game where both left d-pad and left stick need to be used together, but I only have one left thumb so unlikely(? :)"
Same issue here.
Godot v4.1.dev4 (C#).
Mapped the action move_left
to the A key and left joystick to the left. Mapped move_right
to D and left joystick to the right.
Using Input.GetAxis("move_left", "move_right")
while playing with a keyboard sometimes returns 0 and makes the character stop for a fraction of a second before moving again. Playing with the controller works fine. Disconnecting the controller fixes the issue with the keyboard.
This issue was not occurring before I mapped the actions to the joystick (so using only the keyboard works fine)
Any progress on this issue other than jakeymg's workaround? madmiraal's PR (https://github.com/godotengine/godot/pull/47599) seems to work just fine, does it need more testing before merging?
Edit: jakeymg's workaround fixes the issue. Cannot think of why this should fix it other than the joystick axis not actually respecting the deadzone values set.
madmiraal's PR (https://github.com/godotengine/godot/pull/47599) seems to work just fine, does it need more testing before merging?
See https://github.com/godotengine/godot/pull/47599#issuecomment-1474668408.
Godot 4.0 beta 10. Seeing the same issue with the Steam Deck controller when you have d-pad and joystick input mapped to the same action.
@joemicmc you mean the Steam Deck itself, eh? I'm seeing d-pad work fine on PC and a controller connected to that PC, but then Steam Deck w/ linux build D-pad is only working for Menu navigation but not game input. Think it's this same issue?
@hawkerm you can test by removing any other input mappings to your in-game action and just leave the d-pad
@joemicmc yep, will try that next. I did notice that it's specific to the Controller built-in to the Steam-deck. If I connect an external controller (GuilKit) to the Steam Deck, then it's fine.