[Windows] Gamepad Extension [Now part of Stencyl 3.2+]

thiagojabur

  • Posts: 48
Okay, that is weird haha yours works as intended over here. The change they've did on the new JoystickEvent changes nothing at all, I still read the axis from its indexes and bind it to a key. I've added a few trace statements on mapJoyAxisMove. When I press, respectively, left, rigth, up and down this is the output I get:

Quote
[LOG] Gamepad.hx:186: Axis: 0
[LOG] Gamepad.hx:187: Value: -0.6266060366
[LOG] Gamepad.hx:188: Axes array: [-0.6266060366,0.0392773217,0,0.03353984191,-0.08392590106]
[LOG] Gamepad.hx:180: Axis: 0
[LOG] Gamepad.hx:181: Value: 0.7214880825
[LOG] Gamepad.hx:182: Axes array: [0.7214880825,0.0392773217,0,0.03353984191,-0.08392590106]
[LOG] Gamepad.hx:186: Axis: 1
[LOG] Gamepad.hx:187: Value: -0.8230231635
[LOG] Gamepad.hx:188: Axes array: [-0.09811700797,-0.8230231635,0,0.03353984191,-0.08392590106]
[LOG] Gamepad.hx:180: Axis: 1
[LOG] Gamepad.hx:181: Value: 0.7573168126
[LOG] Gamepad.hx:182: Axes array: [-0.1107821894,0.7573168126,0,0.03353984191,-0.08392590106]

In order to see those traces, replace your onJoyAxisMove b this

Code: [Select]
public static function onJoyAxisMove (event:JoystickEvent) : Void {
for (i in 0...(event.axis).length) {
currentPressures.set(i,event.axis[i]);
//check the axis state is currently on a moving position or resting position
if ( event.axis[i] >= joystickSensitivity || event.axis[i] <= -joystickSensitivity) {
//check if the axis was resting before
if (lastAxes.get(i) == null || lastAxes.get(i) == 0) {
//check if the axis is beyond sensitivity
if (event.axis[i] >= joystickSensitivity) {
trace("Axis: " + i);
trace("Value: " + event.axis[i]);
trace("Axes array: " + event.axis);
lastAxes.set(i,1);
if (joystickToControls.get("+Axis " + i) != null) Input.simulateKeyPress(joystickToControls.get("+Axis " + i));
} else if (event.axis[i] <= -joystickSensitivity) {
trace("Axis: " + i);
trace("Value: " + event.axis[i]);
trace("Axes array: " + event.axis);
lastAxes.set(i,-1);
if (joystickToControls.get("-Axis " + i) != null) Input.simulateKeyPress(joystickToControls.get("-Axis " + i));
}
}
} else if (lastAxes.get(i) != null && lastAxes.get(i) > 0) {
lastAxes.set(i,0);
if (joystickToControls.get("+Axis " + i) != null) Input.simulateKeyRelease(joystickToControls.get("+Axis " + i));
} else if (lastAxes.get(i) != null && lastAxes.get(i) < 0) {
lastAxes.set(i,0);
if (joystickToControls.get("-Axis " + i) != null) Input.simulateKeyRelease(joystickToControls.get("-Axis " + i));
}
}
}

You can remove the traces later. It might have to do with sensitivitiy, as you suggested. Try using a higher value for it, closer to 1.

DudeMakingAGame

  • Posts: 306
Is this for Windows? Or for MAC?
I'll try that tonight! Thanks!

Jon

  • *
  • Posts: 17524
If it's built on what OpenFL has built in, it should work for Mac.

DudeMakingAGame

  • Posts: 306
Okay, I updated onJoyAxisMove, left the sensitivity alone, plugged my wireless Xbox 360 controller to my MAC and here's my traces (left,right,up,down).

Quote
[LOG] Gamepad.hx:187: Axis: 0
[LOG] Gamepad.hx:188: Value: -0.8645283364
[LOG] Gamepad.hx:189: Axes array: [-0.8645283364,0.1210669271,-1,-0.0002441480758,-0.07315286721,-1]
[LOG] Gamepad.hx:181: Axis: 0
[LOG] Gamepad.hx:182: Value: 0.937284463
[LOG] Gamepad.hx:183: Axes array: [0.937284463,0.02951139866,-1,-0.0002441480758,-0.07315286721,-1]
[LOG] Gamepad.hx:187: Axis: 1
[LOG] Gamepad.hx:188: Value: -0.9299905393
[LOG] Gamepad.hx:189: Axes array: [0.1499069185,-0.9299905393,-1,-0.0002441480758,-0.07315286721,-1]
[LOG] Gamepad.hx:181: Axis: 1
[LOG] Gamepad.hx:182: Value: 0.8022400586
[LOG] Gamepad.hx:183: Axes array: [-0.2895596179,0.8022400586,-1,-0.0002441480758,-0.07315286721,-1]

So it's definitely getting the events. But after mapping it, the character would still just go straight up and I couldn't change it.
I played around with sensitivity of the listener, in the map configuration actor. If I set it low, .10, some directions would work, but some wouldn't (I pushed right, he moved up).

Just as a test, I took the exact same setup over to my Windows PC, and it worked like a charm right out the gate.
Here's the traces from my Windows box with the same wireless 360 controller (different drivers):
Quote
[LOG] Gamepad.hx:187: Axis: 0
[LOG] Gamepad.hx:188: Value: -0.9231543931
[LOG] Gamepad.hx:189: Axes array: [-0.9231543931,0.06244087039,0,-0.02276680807,0.03817865535]
[LOG] Gamepad.hx:181: Axis: 0
[LOG] Gamepad.hx:182: Value: 0.9152806177
[LOG] Gamepad.hx:183: Axes array: [0.9152806177,-0.01446577349,0,-0.03357036042,0.03817865535]
[LOG] Gamepad.hx:187: Axis: 1
[LOG] Gamepad.hx:188: Value: -0.8677632984
[LOG] Gamepad.hx:189: Axes array: [0.1095919675,-0.8677632984,0,-0.03357036042,0.03817865535]
[LOG] Gamepad.hx:181: Axis: 1
[LOG] Gamepad.hx:182: Value: 0.8864406262
[LOG] Gamepad.hx:183: Axes array: [-0.2346568194,0.8864406262,0,-0.03357036042,0.03817865535]
To be fair, diagonals were a little stiff but I'm sure I can play around with the sensitivity of the listener and fix that.

I still don't know what I'm going to do about MAC though. I'm using the Tattiebogle drivers (http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/OsxDriver) and I'm on Mavericks.

thiagojabur

  • Posts: 48
I have an idea on how to improve diagonals and make them smoother, I will upload it later. But I don't have a MAC to test stuff further :C I will have to keep prompting you, Dude.

DudeMakingAGame

  • Posts: 306
Not a problem! Glad to help out as I'm consuming this for games also.

Is there a sensitivity you think i could try? I don't know if it's a driver issue or not. It's definitely reading my axis movement.

DudeMakingAGame

  • Posts: 306
One other question: right now, if I have more than one controller, both controllers look exactly the same.
How can I see the different controllers and assign their sticks separately?

thiagojabur

  • Posts: 48
Oh, I have to fix that haha just adding the device on the Map will do it. I've also improved the diagonals already, just doing some tweaks to reduce some overhead.

DudeMakingAGame

  • Posts: 306
Cool! Excited to test it out.

thiagojabur

  • Posts: 48
Sorry for taking so long! Got a bit side tracked haha

Okay, here it is, it now lets you use as many devices as you want PLUS the diagonals movement is improved, but you have to set a threshold for it. It is a fine granularity adjusment, when the listener detects that neighbors axes are pressed it will check if those axes have their pressure over sensitivity divided by threshold (sensitivity/threshold). If that happens, then it is considered a diagonal movement, simulating two keypresses at once. That makes diagonal movement WAY smoother, but you have to find some good values for sensitivity and threshold. I'm using 0.4 for sensitivity and 1.4 for threshold (which means that if two neighbor axes have a pressure over 0.28 it is a diagonal movement) and it works quite fine.

Enough blabbering, here it goes: https://dl.dropboxusercontent.com/u/12567731/gamepad.rar

Edit: Forgot to mention. Threshold should be bigger than 1.
Edit2: Also, do not use values bigger than 2. Shaking the controller will make the character move for big values of threshold.

« Last Edit: February 19, 2014, 07:55:44 pm by thiagojabur »

DudeMakingAGame

  • Posts: 306
Not a problem! Thanks. I'll try it out.

kierannolan

  • Posts: 64
Hi

I am trying out this extension (both the first version and the latest) with the sample game (on both windows and osx), but when I try to compile I'm getting the following error:

Confirm Configuration (62) -  Unexpected )

Any help would be greatly appreciated... also does anyone have an example with calibration values hard coded in?

I've attached a screenshot of the block that is highlighted in the IDE from this error

many thanks

DudeMakingAGame

  • Posts: 306
Can you confirm the extension is loaded correctly and turned on?
Post a screenshot of your extension screen.

Thanks!

kierannolan

  • Posts: 64
Hi DudeMakingAGame

It turns out I had 2 versions of the extension going, so I deleted both and just uploaded the latest one
I've also changed the values for joystick sensitivity to 1 and diagonal threshold to 1.4

So now it's going good, I can calibrate the controls, and the little dude is walking in 4 directions and also diagonally (on a mac)

What I'm confused about now is how is how to make these values stick, and get rid of the calibration stage

Also, how can I add in a value for a fire button, and match this to or alongside the keyboard key I'm using for a fire action

many thanks

DudeMakingAGame

  • Posts: 306
Which MAC joypad drivers are you using?