Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity 3D Async polling external hardware in Unity

Tags:

c#

unity3d

I'm using a Wiimote controller as an input device. I'm using this wrapper for HID calls / polling.

In the demo scene that comes with this wrapper, polling the controller is done in the Update event.

In many Wii games aiming extremely up and down quickly triggers an action. The wrapper indicates extreme vertical aiming positions (where the aim goes out of scope / is "offscreen") as

Y=-1

I tried to detect such a rapid up-down movements by

1) Detecting if aim is off-screen
2) If yes, have a look if the aim is within the screen again
3) Detect if aim is off-screen again and if all this happened in a certain time period

The problem however is (I think due to the nature of polling only in the Update event), #2) doesn't necessarily have to occur. It's possible that the aim was in the screen, but the controller wasn't polled when it was.

I would like to ask what might be a valid solution to this problem.

like image 788
tmighty Avatar asked Oct 29 '17 00:10

tmighty


1 Answers

Your polling would have to be pretty bad for this to be an issue, but other than increasing the poll rate, there isn't really anything you can do here.

The only other option would be to use the gyroscope or accelerometer instead (sorry, didn't bother to check if your wrapper exposes those). You could essentially combine a harsh vertical shake with the point being off screen, but if your polling is an issue in the original solution, it will still probably be an issue here too.

like image 67
Mars Avatar answered Oct 18 '22 00:10

Mars