Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input.is_action_just_pressed flickers when action is tied to an input axis (joystick direction) #81975

Closed
mieldepoche opened this issue Sep 20, 2023 · 7 comments · Fixed by #82056

Comments

@mieldepoche
Copy link
Contributor

mieldepoche commented Sep 20, 2023

Godot version

4.2.dev5

System information

linux, wired switch pro controller

Issue description

may be related to #81170 (as before that, my axes were getting stuck, but since then I get this bug). (although I didn't bisect or anything, I just remember that)

I have an action tied to an input axis (a joystick direction).
This happens as I move my joystick in the direction of the action:

simplescreenrecorder-2023-09-20_13.57.30.webm

(red circle is deadzone)

Steps to reproduce

  1. assign a controller axis to an action
  2. print Input.is_action_just_pressed("your_action") in _process
  3. wiggle your stick

Minimal reproduction project

axis_jittering.zip

@mieldepoche
Copy link
Contributor Author

it is counting the amount of times that a certain action is pressed at the same time

not 100% sure but I think that if you assign two keys to an action (say, the left key on your keyboard and the left dpad of a controller), pressing them together can only be tracked correctly that way.

@ErezShahaf
Copy link
Contributor

ErezShahaf commented Sep 20, 2023

it is counting the amount of times that a certain action is pressed at the same time

not 100% sure but I think that if you assign two keys to an action (say, the left key on your keyboard and the left dpad of a controller), pressing them together can only be tracked correctly that way.

In that case I can't understand intentions of the developers:

// If axis is already pressed, don't increase the pressed counter.

Then what is the point of having this counter anyway? It won't count the amount of concurrent presses, and line 731 will be meaningless as well - as the maximum is 1. I can see how the bug lies in there and would love to fix it, but I'll wait to hear from others what's the idea of that counter because there may be something that I'm missing.

@Sauermann
Copy link
Contributor

Then what is the point of having this counter anyway?

The counter tracks how many different keys are pressed, that are bound to the same Action.

// If axis is already pressed, don't increase the pressed counter.

That is to make sure that input from a single Axis can affect the counter only once.

The jittering likely got introduced in this PR: #80859 (comment) CC @KoBeWi.

@ErezShahaf
Copy link
Contributor

Then what is the point of having this counter anyway?

The counter tracks how many different keys are pressed, that are bound to the same Action.

// If axis is already pressed, don't increase the pressed counter.

That is to make sure that input from a single Axis can affect the counter only once.

The jittering likely got introduced in this PR: #80859 (comment) CC @KoBeWi.

Makes sense, I'll look into it.

@KoBeWi
Copy link
Member

KoBeWi commented Sep 20, 2023

That is to make sure that input from a single Axis can affect the counter only once.

To expand on this, an axis can press an action multiple times in a row without releasing it. This is because axis events come with a strength and they count as pressed when the strength is above deadzone. You can get multiple events with strength above deadzone.
This condition checks only axis input, as buttons and keys are unaffected.

@ErezShahaf
Copy link
Contributor

ErezShahaf commented Sep 21, 2023

It ended up being a fairly simple issue, the assignments of pressed_frame were in the wrong scope; it works perfectly now.
Btw, unrelated question - when I tried to debug the issue from source whenever I open the test project of miel it would detach the debugger. Is there a way to solve it?

@KoBeWi
Copy link
Member

KoBeWi commented Sep 21, 2023

Use --path and provide path to the project. You need to open it without starting project manager, because it's a separate process.

@akien-mga akien-mga added this to the 4.2 milestone Oct 9, 2023
ProbablyWorks pushed a commit to ProbablyWorks/godot that referenced this issue Oct 22, 2023
Pressed tick assignments were in the wrong scope, resulting in updating
`pressed_frame` even when it shouldn't and therefore the `just_pressed`
would return true every time that the strength changes and not only when
there's a new valid press.

Fixes godotengine#81975.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants