-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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 - add get_action_peak_strength() #78176
base: master
Are you sure you want to change the base?
Conversation
Thanks for the contribution! I am not super convinced this should be added. I understand the rationale of allowing to retrieve the strength there, but the first thing I see is the fact it makes the API a bit hard to understand and adds a bit of bloat. But my main problem with it is: what is it useful for ? When you use But well, if we want it anyway. I would instead provide two other functions instead of an argument the two |
Think of it like pressing a jump button, and it registers how hard you've pressed it. Or a fighting game that registers how hard you press punch button or something. This does depend on whether controllers / APIs we currently support (and OSes) have this feature. If not, it would not be necessary. But I know e.g. music controllers have velocity sensitivity. I know L / R trigger buttons on gamepads support "pressure" (i.e. how far you pull them in usually) but velocity for normal buttons I'm not sure. Pressure for trigger buttons I don't think would be super useful for short presses, so I'd appreciate any feedback for the status with normal buttons. I did initially add this as two extra functions as you describe, and that would be fine too. Maybe there's an even better way of passing this info (like combining it in a This is what google bard had to say: 😁
That's just google bard, I haven't looked at the details of the APIs, how true this is I don't know. Gamepad API in javascript seems to support this via pressure:
It might turn out that doing it via "pressure" is the only way of doing it, as opposed to velocity (which for example MIDI uses). The only question is whether for a quick press we might need to detect "peak pressure", as it might report a lower pressure during the release. I'll try and find out better whether any APIs support this, and would appreciate any info from those more familiar with the various current input APIs. If it turns out there is no decent API support, I'll close this, but will leave open for a few days to see if we can find out the current situation. |
I don't deny that it can be useful to know how hard a button has been pressed. And I think some controllers already provide that. My only concern is about it is in the context of a less-than-one-frame event. I think that, in such a case, it might not be very relevant. Like, as a dev, if you are interested in the transition from 'not pressed' to 'pressed', I am not sure how relevant would be a strength for such a small amount of time, as users would not really be able to control the pressure anyway. For more than one frame, you can, for example, smooth the strength over several frames to let users control the pressure, but for a single frame, the value might be quite irrelevant IMO.
That's an issue with several things in the API. There's no real way to return structs by value. We may be able to return a RefCounted object but that's not really efficient I guess ? (I say that because it's not used often in the API, so TIWAGOS). In the end I guess two new functions would be better and probably more consistent that most of our APIs. |
We must consider that not input will be at 60fps. At a low frame rate, or during a slow frame, or at low physics tick rate (e.g. I use 10/15 tps for some games with interpolation) where I'm actually coming round to the idea that storing a peak strength per action might be more useful for this, as if a button only supports pressure, it removes the problem of a spurious low pressure input following the max pressure of a press, so I'll change the PR to do this, and add a separate function instead of the extra parameter. Getting a peak strength for an action could also be potentially useful outside of the short press scenario.
Yup it can be a pain. For a button press actually I don't think there would be a massive need for Maybe a new function I'll try this, but again, depends on whether there is API support. I'll try this out on my gamepad. UPDATE: PR now updated to have this new |
This PR records the peak strength over each press, which can be read after release, and therefore enables the user to know how hard button was pushed in short presses. This was previously impossible to read after short presses, because strength is reset to zero on release.
3f5d80c
to
99e6164
Compare
This PR records the peak strength over each press, which can be read after release, and therefore enables the user to know how hard button was pushed in short presses. This was previously impossible to read after short presses, because strength is reset to zero on release.
Following from #77055 , I'm including this in a separate PR as it deserves separate scrutiny as it is a subtle issue.
Discussion
Although #77055 allows detection of quick action presses and releases (for jump keys etc), there is one situation which it doesn't solve, that is, getting the action
strength
andraw_strength
of these quick presses. The problem is that the existing code setsaction_strength
andraw_action_strength
to ZERO on release. While this works in most situations, with a quick release, it means that if you attempt to find thestrength
of a button press, the result will be zero, and this information has effectively been lost.This PR solves the problem by introducing a new function to get the peak strength of an action, which is not reset on release, and can thus be read after a short press (after release).
Storing the peak strength should provide a more reliable measure of how hard the button was pressed, in case several strengths are updated to an action before release.
Notes