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

Improve X and Y input calculations for joystick corners. #33

Closed stspdotname closed 7 years ago

stspdotname commented 8 years ago

When the joystick is moved into a corner, the X and Y vectors should not be added linearly. Doing so results in a disproportionate amount of force being applied to in-game movement at 45-degree angles.

This leads to problems in Ocarina of Time, for example. By slightly moving the joystick horizontally or vertically, Link will slowly and carefully tiptoe into the indicated direction. But tiptoeing along a path at a 45-degree angle is impossible because Link will start jogging as soon as the joystick is moved. (Without this patch, the problem is especially visible if X and Y inputs are capped at a low value such as 20 or 40.)

This behaviour makes it impossible to get at the Megaton Hammer in the Fire Temple. A narrow winding staircase has to be climbed quickly within about 15 seconds, but Link will all too easily fall off the edge if the game is played with the input-sdl plugin.

This patch smoothes X and Y inputs in corners such that the directional forces applied by the joystick form a circle, rather than a square. This matches the N64 hardware behaviour more closely. The Megaton Hammer is now within reach!

Patch by myself and Neels Hofmeyr.

richard42 commented 8 years ago

okay, I see what you're doing here and in principle I think this could be a good idea, but I see some potential issues. wITH adaptoid converters and similar which connect a real N64 controller to the computer, this will result in diminished velocity at angles away from the X and Y axes. I can see an easy fix for this, but can you explain why you are forcing axis values with an absolute value between 1 and 9 to have an absolute value of 10? This might cause problems in some games.

neeels commented 8 years ago

Context: basically we hacked this up after failing to get the Megaton Hammer for an impossibly long time. The patch has gathered some dust before stsp decided to at least publish it before it gets forgotten. Looking at it today, the math admittedly looks a bit weird to me. The initial simpler math didn't work out so I tried to pull math tricks out my sleeve while we were going. I'd like to plot it and maybe fix it up, if I had the time.

If it indeed changes the value range, that would be a bug.

I wonder whether real N64 controllers do this kind of, let's call it, circular limitation by physical limitations, so that away-from-x-and-y never even sends maximum x and y values. The conditionals on the length might be related, but again, I suggest the mathematical details need a thorough review (and deserve some comments).

I'd love to do that some day but it will not be until some weekend some time in the future...

So if you or anyone else would like to have a go at it, you'd be very welcome! :)

stspdotname commented 8 years ago

For the record: We were using a Tomee N64 USB controller.

richard42 commented 8 years ago

I'm wondering the same thing about physical limitations in the n64 controller, and whether they prevented the controller from reporting full scale values from both axes at the same time when the analog stick was pressed in a corner. I will test this with a real N64 controller and merge in a fix if this is the case.

richard42 commented 8 years ago

Okay, I got an N64 controller and a mayflash usb adapter and tested this. The N64 controller does not restrict the axis ranges to a circle, but it's not a square either. It's more like an octagon with the points at the cardinal directions. I can probably model it with some relatively simple quadratic equation and apply this as a limit to the axes in mupen64plus. If I do this, can you test to see if it still allows you to get the hammer in OOT?

stspdotname commented 8 years ago

Sure, I should still have the save game somewhere :-)

Thanks for looking into this, Richard!

richard42 commented 8 years ago

I just pushed a change which applies limits to the joystick coordinates in a similar shape as the controller case enforces physically on a real N64 controller. I also put the program I write to find the curves and a screenshot showing the graph into the tools folder of the core module. Can you please test with these latest changes and report your results? I tested OOT and I could walk slowly diagonally (with a Logitech Dual Action wired controller) with both the old code and the new. If you have trouble with this, your deadzone values may be too low.

neeels commented 8 years ago

Excellent! We'll let you know as soon as we got around to testing it; might be a little while until we get a chance though, give us three weeks or so.

stspdotname commented 7 years ago

hammer

richard42 commented 7 years ago

I take it that the change that I made has fixed your problem then?

stspdotname commented 7 years ago

Indeed it has fixed it. Thank you very much for your work!