Gamepad library

It's I decided to make a library that adds the ability to use a gamepad (or controller) in snap.

Features:

Here's the list of blocks


(tip, you can drag and drop the image into snap to get the library)

The gamepads reporter reports the gamepads that it detects. It may not detect the gamepads the first time you run it, but it should the next time.

I created the pov dpad () block because I have a controller that uses an axis for the dpad, and that was the only way I could detect the direction I pressed.

clamp is to normalize joysticks.

deadzone makes an axis (or list of axes) have a deadzone, as well as (hopefully) smooth it.

rumble makes the controller rumble, only if it supports rumble (will probably error if it doesn't, I need to test that).

show analog stick displays 2 axis on stage as an analog stick. This is used in the project to demo the library.


Here's where I got my info from Using Gamepads and Joysticks in JavaScript

Project link
https://snap.berkeley.edu/snap/snap.html#present:Username=ego-lay_atman-bay&ProjectName=gamepad

Cool library, and impressive. What's the purpose of the
untitled script pic (14)
block?

I don't get what

means.

It's to make all joy sticks be in a circle, because some joysticks can go outside the regular area for a joystick.

update: I fixed a few blocks

well, here's a video showing why we need clamping, and what it is.

nice!

Ahh okay. Are you using a gamecube controller because the octagon track of the joystick looks like one. Also I didn't know you make Mariokart content.

The controller I'm using is a nintendo switch usb controller. I don't know why it's like that, but it is.

off-topic

yes, most of my content is mario kart tour. Since I play it every day, I'm able to make videos of it.

Update: made the deadzone block way better.

Update: I added a rumble block. Now you can make controllers rumble in your games. I've only been able to test it because I got a Bluetooth adapter for my computer, so now I can use my joycon on my computer.

I also added a global variable to auto import the extension (this only works if you have js enabled, or have a userscript to whitelist my extensions url).

Cool update. Really though, I wish it was a library so that JS extensions didn't have to be on.

I wish it were too, I mean, it is similar to the robot extensions, but probably more usable since more people have gamepads. Technically all the snap devs need to do is whitelist the extension url, then it'll work without js enabled.

It's a shame there isn't (yet) a good method of allow listing extensions like this

Obviously, you seem to be trustworthy, long time community member but at the moment, only a small number of educational sources are on that list.

I'm lucky , the MQTT extension has been folded into the main libraries but that leads to it's own problems..

If a bug is found, I can't directly patch and fix it and make it available ASAP. It requires me to make a PR and Jens to merge it (which at least gets it into dev version) and then for Jens to make a new release before everyone gets the fix.

Now Jens (hopefully) trusts me and he could allow list one of my GitHub repositories but the problem with that is that it could get hacked by someone. Or I could delete it or I could sneak in another block that doesn't really have anything to do with MQTT

I've been thinking about this issue for a long time but haven't come up with any acceptable, workable method of doing it :frowning: