-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Allow getting Input "axis" and "vector" values by specifying multiple actions #42976
Conversation
@groud What is the correct way to get the raw input amount and deadzone amount for a particular action? There doesn't seem to be an API for this, and the deadzone truncation is very deep.
Should I add an API for this to |
Yep, that's why it's a tricky problem. We may require the user to set the deadzones to zero then add a custom deadzone on top of it, but I really don't like this idea as it is not an obvious behavior. Instead, I believe that we should store a "raw_strength" along the "strength" in the input map, so that we can make our custom computations in the get_vector() function. This requires some changes here and there but it should not be that hard to implement I believe (basically, it's copying what we do with the strength value but without applying the deadzone) |
3647485
to
268ec66
Compare
I think the behavior is good now. I tested it with a Steam controller and it works nice. The first commit by itself is a "just a wrapper over get_action_strength" implementation like when I first submitted the PR, and the last 2 commits change this to handle deadzones nicely as described above. Note that currently it uses the deadzone value from the positive X action only. I think implementing a stretched circle would be way overcomplicated and wouldn't actually provide any real world benefit. What remains is to decide on what order the arguments should be. The current order of (positive, negative) was mostly for similarity with subtracting two |
That is exactly what I wanted to avoid. This is doing a quite unpredictable thing behind the user back. If we don't provide a per half axis deadzone (with such a stretched circle), then we should ask the user, in the get_vector() function, to provide the deadzone override.
I agree, let's ask for more opinions on this then. |
8e2fba6
to
bc6ede7
Compare
43c9934
to
ebae03b
Compare
@groud I made the negative/positive change and I think this is ready for review now. As for the deadzone, now it can either be manually specified, or if a negative value is passed in (default is |
For get_vector, use raw values and handle deadzones appropriately
ebae03b
to
4abf189
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, people are going to be happy with that. :)
Thanks! |
@@ -149,6 +149,9 @@ void Input::_bind_methods() { | |||
ClassDB::bind_method(D_METHOD("is_action_just_pressed", "action"), &Input::is_action_just_pressed); | |||
ClassDB::bind_method(D_METHOD("is_action_just_released", "action"), &Input::is_action_just_released); | |||
ClassDB::bind_method(D_METHOD("get_action_strength", "action"), &Input::get_action_strength); | |||
ClassDB::bind_method(D_METHOD("get_action_raw_strength", "action"), &Input::get_action_strength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@groud Do you remember if this was supposed to be bound (or we can re-decide now I guess)? It seems that I bound this incorrectly, but I'm not even sure that it should be bound. If so, this needs to be get_action_raw_strength
, and also a string needs to be added to the if statement in get_argument_options
(branch).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, it's indeed bound incorrectly.
I don't think accessing the raw value is needed anymore, now that we have get_vector() or get_axis(). But I guess it does not hurt that much to expose it I guess, if anyone want to implement their own deadzone system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #50789
Implements and closes godotengine/godot-proposals#519
In a nutshell, this PR allows shortening this:
To this:
And (roughly) this:
To this (a deadzone can also be specified):
Some discussion remains on what to do with the deadzones forget_vector
. @groud Let me know what you think the best approach is for this. As it is now, it behaves exactly like the above code claims, which many Godot projects already use.Minimal test project: InputGetAxisTest.zip