-
Notifications
You must be signed in to change notification settings - Fork 115
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
Add sensitivity #377
Add sensitivity #377
Conversation
Continuing from #322
I don't think it would necessarily disallow a resource, as mouse motion is a |
Is there any way to tell the difference from, say, a controller stick and mouse motion |
Changing the code // This actually only gets the `UserInput` so there is quite a bit of matching needed to get to a Dual/Single Axis
let input = map.get(Action::Look).get_at_mut(0).unwrap(); with let input = map.get_with_type(Action::Look, LeftStick) seems really nice, but I can't think of a way to say "I want the left stick for this action" or "I want the mouse motion for this action". The closest to this is |
After a bit of testing, this is the current way to change input from an fn change_input_values(mut query: Query<&mut InputMap<Action>, With<Player>>){
let mut input_map = query.single_mut();
// Added `.get_mut()` to `InputMap` to allow this
let input = input_map.get_mut(Action::Look).get_at_mut(0).unwrap();
if let UserInput::Single(kind) = input{
if let InputKind::DualAxis(dual_axis) = kind{
println!("X: {}, Y: {}, Shape: {:?}", dual_axis.x.sensitivity, dual_axis.y.sensitivity, dual_axis.deadzone);
dual_axis.x.sensitivity = 0.8;
dual_axis.y.sensitivity = 0.8;
dual_axis.deadzone = DeadZoneShape::Rect { width: 1.0, height: 1.0 }
}
}
} It is a little on the gross side, but I can't really think of a good way to select with input you want to modify. The first parameter is |
@@ -30,6 +30,8 @@ pub struct SingleAxis { | |||
pub negative_low: f32, | |||
/// Whether to invert output values from this axis. | |||
pub inverted: bool, |
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.
We can replace inverted
with a negative sensitivity value.
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.
We could do this mathematically, but I think it makes the API a lot less clear. I think we should keep them separate, and add some kind of non-negative constraint on sensitivity (or at least a warning).
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.
Okay, fair. Let's do that then.
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.
Sorry, but what does "that" refer to? I'm guessing merging sensitivity and inverted as you said below, but what to do about making the API less clear, as plof27 said. I'm guessing just write useful docs on sensitivity to explain how inverting works now? I think this is addressed by leaving invert()
functions for use, as it uses the same API as before. It's just inverted means reversing the sign instead of flipping a bool.
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.
As a side note, instead of removing the invert functions, I can just invert the sensitivity to do the same thing.
/// Returns this [`SingleAxis`] inverted.
#[must_use]
pub fn inverted(mut self) -> Self {
self.sensitivity = -self.sensitivity;
self
}
This helps to keep the ergonomics of the invert bool without having it
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, I like that :)
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, I like that :)
So, would you like that re-merged into one value? Or, close this as resolved and keep them separate. I am good with either solution.
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.
Alright, that's more straightforward than I expected. I'm not super concerned about being able to tweak these values later, the fact that it's possible to at all is about good enough for me.
We should collapse the inverted
field into sensitivity
, write up a change log and add some tests before merging and shipping this though.
Ok, I will get on that and all the changes presented :). Do you want a new example for how to change values at runtime, punt it to a new pr, or just not have an example? Also, do you want to include |
@plof27 convinced me: let's revert the change to merge inverted + sensitivity. It's technically correct, but a less clear API. Add |
Should I add "some kind of non-negative constraint on sensitivity (or at least a warning)" as plof27 said? If so, where would that go, as there a many ways of creating an axis. Should I add just a doc on sensitivity that says negative values will invert it, so keep the values |
I'm not fully sure where this should go. We could put it on every constructor / setter? But that's pretty duplicative, and would force us to fully lock down the construction. We could also use a custom I'm tempted to just add it to the docs for now and get this merged and shipped. |
Agreed |
Co-authored-by: Alice Cecile <[email protected]>
Closes #322
The design of the how to implement sensitivity was partly discussed in #322. However, I will paste my design comment for easy reading.
How to add the multiplier to inputs
My design would be something like this:
The value passed in for
with_sensitivity()
would be a multiplier, 1.0 would be the default.Where to apply the multiplier
It might be possible to place it in
input_value()
ininput_streams.rs
. It would look something like this:Every axis, as far as I know, uses
value_in_axis_range()
, so it might be as easy as just adding* axis.sensitivity
. Also, from looking around a bit, every input seems to at some point callinput_value()
. So, calculating the sensitivity there will make sure all inputs will be modified if needed.Where to store the data
I was thinking we could store the sensitivity value in
SingleAxis
asDualAxis
is just twoSingleAxis
. Then, we could add constructor methods as shown above for bothSingleAxis
andDualAxis
.How to change the data
I think a way to change the sensitivity would be to query for
InputMap
and useget()
. It does return&PetitSet<UserInput, 16>
so that may be hard to work with as you have to index into the correctUserInput
. I don't know if there can even be an easy way to do this. Do users have to look up to order they inserted theUserInput
intoInputMap
to change the correct one? This is still an open question that I would love to hear about!Things left to do:
PartialEq
andHash
forSingleAxis