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
Expose analog joystick input to the Lua API #14348
base: master
Are you sure you want to change the base?
Conversation
5f7f8cf
to
286254d
Compare
In general, I think it might be more desirable to make this work similar to how a physical joystick does in code by having two axes, X and Y, that range from [-1, 1]. It makes it consistent with how these things usually work, and you already effectively convert to that anyway by using sin and cos in your code example. |
The problem with this approach is that for making it intuitive/understandable, we'd have to name the new fields To avoid this, you could call them |
I think that having |
TBH, I'm still not sure which API is better - the current one forces modders to think, so maybe they're less likely to make the mistake you're describing. Both API designs, the current one or your suggestion, would be fine for me. |
I think that |
I've updated the API, thanks for your input. |
Haven't looked at the code but I wanted to note that it's important that across all combinations of old/new servers/clients the server sees the direction keys being "pressed" if the player uses the analog stick to move. And I suppose with this PR there's a new requirement: If I move using direction keys the server should still see matching values for the analog stick. |
It would also be nice for mods to be able to read whether the input was made with a keyboard or using a touchscreen/joystick; then mods/games that (ab)use movement input for other purposes would be able to set up different control schemes based on whether the player uses keyboard or touchscreen input. |
sfan5: I think both requirements are fulfilled by this PR and I have done some testing with different old/new server/client combinations, but I'd be thankful if you or someone else could also verify that this works as expected. y5nw: That's a different issue, see #12264. |
9516df6
to
9354f8e
Compare
9354f8e
to
8875916
Compare
This PR exposes analog joystick input to the Lua API. This allows games like PRANG! to have better movement. It adds two new fields,
movement_x
andmovement_y
, toplayer:get_player_control()
.These fields are set according to keyboard input when not available:
To do
This PR is a Ready for Review.
How to test
Verify that keyboard input still works.
Install PRANG! from ContentDB on an Android device and apply this patch:
Play PRANG! and enjoy the virtual analog joystick. (Should probably use
math.ceil
here.)