mupen64plus / mupen64plus-input-sdl

Input plugin for Mupen64Plus v2.0 project using SDL. This is derived from the original Mupen64 blight_input plugin.
GNU General Public License v2.0
43 stars 70 forks source link

[BUG] Key Modifier when pressing a diagonal #120

Closed Marcelo20XX closed 1 year ago

Marcelo20XX commented 1 year ago

The keyboard's key modifier bugs when pressing a diagonal direction, i.e. when I press up on the key assigned to the up direction of the stick it decreases the movement by the given factor, but if I press a diagonal the modifier bugs out and give me a wrong value and doesn't decrease the movement by the same amount...

This cause the player to move at different speeds when pressing a direction or a diagonal, ideally the movement speed value should be the same between a direction and a diagonal...

richard42 commented 1 year ago

I just looked over the code for handling keyboard mapping for the analog stick, including the Right-Control and Right-Shift modifier handling, and it looks like it is correct. Maybe this is related to the specific game that you are playing which exhibited the problem. Which game(s) have you observed this problem with?

Marcelo20XX commented 1 year ago

https://user-images.githubusercontent.com/15281206/211419699-54e725cd-0a6d-41e9-b5b0-ce7482628172.mp4

It happens in all the games... I think the problem lies in the coordinates of the analog stick when using a modifier and pressing two directional keys...

In another project they implemented a solution like this and it works slowing the movement by the same amount:

if (pad->stick_x != 0 && pad->stick_y != 0) {
    double angle = atan2(pad->stick_y, pad->stick_x);
    pad->stick_x = cos(angle) * abs(pad->stick_x);
    pad->stick_y = sin(angle) * abs(pad->stick_y);
}
richard42 commented 1 year ago

Okay I just pushed a change which should fix this. Can you build from the latest source and test for me?

Marcelo20XX commented 1 year ago

Yes @richard42 that fixed it, thank you very much. Now it behaves as it should.

richard42 commented 1 year ago

Great!