-
Notifications
You must be signed in to change notification settings - Fork 2.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
Expose analog joystick input to the Lua API #14348
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
@grorp If this affects clientside player movement then it needs a server-imposed deadzone. The reason is that you might want to enforce a minimum speed; the old movement implicitly has that in the form of the sneak speed. so this is a subtly breaking change. If you can't see why that's a problem, imagine having to animate a walk cycle for someone moving at 0.01 nodes per second. Remember that we do not yet have animation mixing, so you can't just interpolate between idle and walking (not that it necessarily looks good) - all you can do is adjust the speed, so you have to choose between letting people slide around slowly in an idle animation, or display a freeze-frame of the walking animation. Neither looks very good. If you have physics such as waving hair baked into the animation, you should never play it slowed down. I'm aware of the existing edge case created by walking into a wall, but that one is a bit less jarring than letting people perform this weird jitter on flat ground by nudging the analog sticks repeatedly. |
@hecktest This PR doesn't change player movement. Player movement already respects analog joystick input on the master branch. This PR is concerned with making analog joystick input accessible to the Lua API. |
e6379c2
to
62e245f
Compare
@@ -1060,10 +1062,13 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket * | |||
[12+12+4+4+4] u8 fov*80 | |||
[12+12+4+4+4+1] u8 ceil(wanted_range / MAP_BLOCKSIZE) | |||
[12+12+4+4+4+1+1] u8 camera_inverted (bool) | |||
[12+12+4+4+4+1+1+1] f32 movement_speed |
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.
[12+12+4+4+4+1+1+1] f32 movement_speed | |
[12+12+4+4+4+1+1+4] f32 movement_speed |
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.
hmm, I think the current version is actually correct since it's an offset, not a size
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.
Tested with a real analog joystick, works as expected. I can attest that this makes PRANG! quite enjoyable. Code looks good.
(I noticed some joystick annoyances (for example, axes are bound pretty randomly with no way to change this; joystick input persists after you plug out the joystick, you need to restart Minetest), but that's not this PR's issue. I think we need #12888 for joysticks to work well.)
c97857b
to
dc78344
Compare
I did some backwards compat tests again, all with a new server and modified PRANG! as described in the top post:
So that still seems to work correctly. |
Is |
if (pkt->getRemainingBytes() >= 1) | ||
*pkt >> bits; | ||
|
||
if (pkt->getRemainingBytes() >= 8) { | ||
*pkt >> player->control.movement_speed; |
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.
It indeed looks like movement speed should be clamped between 0 and 1 here
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.)